def make_chart(self,filename):#pyechart #变量此时的数据类型:<class 'numpy.ndarray'>,需转化为列表 (time,confirm,heal,dead,add,suspect)=np.loadtxt(filename,\ skiprows=1,\ dtype='str',\ delimiter=',',\ usecols=(0,1,2,3,4,5),\ unpack=True) #新建图表 chart =Line()#init_opts=opts.InitOpts(theme=ThemeType.LIGHT) #设置图表标题 chart.set_global_opts(title_opts={"text": "全国NCP疫情趋势图", "subtext": self.timeNum})# #设置x,y轴 chart.add_xaxis([i[-4:] for i in time]) chart.add_yaxis("确诊", list(confirm),symbol=" ",is_symbol_show=True)#,is_connect_nones=False chart.add_yaxis("治愈", list(heal)) chart.add_yaxis("死亡", list(dead)) chart.add_yaxis("新增确诊", list(add)) chart.add_yaxis("疑似病例", list(suspect)) chart.width=100 chart.page_title="NCP疫情动态" chart.theme="black" #保存为本地文件 # render 会生成本地 HTML 文件,默认会在当前目录生成 render.html 文件,bar.render("mycharts.html") make_snapshot(snapshot, chart.render("main.html"), "main.png") os.startfile(os.getcwd()+"\\main.html")#打开文件
def make_chart(self): (year,population,men)=np.loadtxt("中国70年人口数据.csv", dtype="str", delimiter=",", skiprows=(1), usecols=(0,1,2), unpack=True) year=list(year)[::-1] population=list(population)[::-1] chart=Line() chart.add_xaxis(year) chart.add_yaxis("总人口(人)",population) # c = Line().add_xaxis(year).add_yaxis("总人口(人)", population) # chart.overlap(c) chart.width=100 chart.render("main.html") os.startfile(os.getcwd()+"\\main.html")#打开html文件 print(population)