首先要用“pip install pyecharts ”命令安装好包,然后再运行下边程序
import pyecharts from pyecharts.charts import Bar from pyecharts.charts import Pie from pyecharts.charts import Line from pyecharts import options as opts #设置参数 bar=Bar()#创建一个柱状图对象 bar.add_xaxis(["衬衫","毛衣","裙子","风衣","T恤"]) #用列表来保持 bar.add_yaxis("A商家销量",[150,67,95,78,99]) #添加y轴数据 bar.add_yaxis("B商家销量",[170,167,145,28,19]) #添加y轴数据 bar.add_yaxis("C商家销量",[120,67,125,58,89]) #添加y轴数据 bar.set_global_opts(title_opts=opts.TitleOpts(title="商场销售情况")) #设置标题 bar.render("商场销售柱状图.html") pie=Pie() #创建饼状图对象 cate = ['苹果', '华为', '小米', 'Oppo', 'Vivo', '魅族'] data = [153, 124, 107, 99, 89, 46] dataList=[] #数据处理 for i in range(0,len(cate)): d=[cate[i],data[i]] dataList.append(d) pie.set_global_opts(title_opts=opts.TitleOpts(title="手机销售情况")) pie.add("单位:万台",dataList) pie.render("手机销量饼图.html") #生成折线图 line=Line() x=["1月","2月","3月","4月","5月","6月"] y1=[100,200,300,200,100,400] y2=[50,100,200,300,400,100] line.add_xaxis(xaxis_data=x) line.add_yaxis(y_axis=y1,series_name="深圳") line.add_yaxis(y_axis=y2,series_name="长沙") line.set_global_opts(title_opts=opts.TitleOpts(title="降雨量折线图")) line.render("降雨量折线图.html")