from pyecharts. charts import Line
line = Line( )
f = open ( "D:/text.txt" , "r" , encoding= UTF- 8 )
data = f. read( )
data = data. replace( "213xa41232_2231" , "" )
data = data[ : - 2 ]
import json
dict_data = json. loads( data)
trend_data = dict_data[ 'data' ] [ 0 ] [ 'trend' ]
第七步:进一步获取数据,生成X轴, Y轴( 不显示数字) :
from pyecharts. options import LabelOpts
X_data = trend_data[ 'updateDate' ] [ : 314 ]
Y_data = trend_data[ 'list' ] [ 0 ] [ 'data' ] [ : 314 ]
line. add_xaxis( X_data)
line. add_yaxis( "确诊人数" , Y_data, label_opts= LabelOpts( is_show= False ) )
注:数据的获取,取决于字典的结构
from pyecharts. options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
line. set_global_opts
(
title_opts = TitleOpts( "2020确诊人数" , pos_left= "center" , pos_bottom= "1%" ) ,
legend_opts= LegendOpts( is_show= True ) ,
toolbox_opts= ToolboxOpts( is_show= True ) ,
visualmap_opts= VisualMapOpts( is_show= True )
)
line. render( )
f. close( )