Python+pyecharts繪制雙動(dòng)態(tài)曲線教程詳解
總體跟官方樣例相似,但是官方樣例因?yàn)椴糠执a有誤無(wú)法運(yùn)行,同時(shí)需要了解json,以及前后端知識(shí)需要一些時(shí)間,因此供大家參考。
這個(gè)是views
def line_base() -> Line: line = ( Line() .add_xaxis(list(range(10))) .add_yaxis(series_name="專注度", y_axis=[randrange(0, 100) for _ in range(10)],areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) .add_yaxis(series_name="放松度", y_axis=[randrange(0, 100) for _ in range(10)],areastyle_opts=opts.AreaStyleOpts(opacity=0.5)) .set_series_opts() .set_global_opts( title_opts=opts.TitleOpts(title="專注度和放松度"), xaxis_opts=opts.AxisOpts(type_="value"), yaxis_opts=opts.AxisOpts(type_="value"), ) .dump_options_with_quotes() ) return line class ChartView(APIView): def get(self, request, *args, **kwargs): return JsonResponse(json.loads(line_base())) cnt = 9 cnt1 = 9 class ChartUpdateView(APIView): def get(self, request, *args, **kwargs): global cnt,cnt1 cnt = cnt + 1 cnt1 = cnt1 + 1 return JsonResponse({"name": cnt,"value": randrange(0, 100),"name1":cnt1,"value1":randrange(0, 100)})
這個(gè)是urls界面
path('index/',views.Index), path('line/', views.ChartView.as_view()), path('lineUpdate/', views.ChartUpdateView.as_view()),
html
function fetchData() { $.ajax({ type: "GET", url: "http://127.0.0.1:8000/line", dataType: "json", success: function (result) { var options = result.data; line.setOption(options); old_data = line.getOption().series[0].data; old_data1 = line.getOption().series[1].data; } }); } function getDynamicData() { $.ajax({ type: "GET", url: "http://127.0.0.1:8000/lineUpdate", dataType: 'json', success: function (result) { var options = result.data; old_data.push([options.name, options.value]); old_data1.push([options.name1, options.value1]); line.setOption({ series: [{ data: old_data }, { data:old_data1 } ] }); } }); }
效果如圖所示,這里葉修改了Line圖的風(fēng)格
到此這篇關(guān)于Python+pyecharts繪制雙動(dòng)態(tài)曲線教程詳解的文章就介紹到這了,更多相關(guān)Python pyecharts雙動(dòng)態(tài)曲線內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
10個(gè)使用Python必須知道的內(nèi)置函數(shù)
這篇文章小編主要向大家介紹的是10個(gè)使用Python必須知道的內(nèi)置函數(shù)reduce()、split()、map()等,更多后置函數(shù)請(qǐng)看下文2021-09-09Python機(jī)器學(xué)習(xí)入門(五)之Python算法審查
這篇文章主要介紹了Python機(jī)器學(xué)習(xí)入門知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08Python 項(xiàng)目轉(zhuǎn)化為so文件實(shí)例
今天小編就為大家分享一篇Python 項(xiàng)目轉(zhuǎn)化為so文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12Python實(shí)現(xiàn)常見(jiàn)數(shù)據(jù)格式轉(zhuǎn)換的方法詳解
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)常見(jiàn)數(shù)據(jù)格式轉(zhuǎn)換的方法,主要是xml_to_csv和csv_to_tfrecord,感興趣的小伙伴可以了解一下2022-09-09