做一个面积图和折线图
import pyecharts.options as opts
from pyecharts.charts import Line,Page
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType
def line_gongguan():
data_y = ['1.11%','0.36%','0.87%','0.30%','0.93%','1.09%','0.33%','1.09%',
'10.11%','1.95%','0.29%','0.60%','0.26%','1.16%']
data_y_0 = [float(x.strip('%')) for x in data_y]
line = (
Line(init_opts=opts.InitOpts(theme=ThemeType.DARK,chart_id=1))
.add_xaxis(['SY\nERQ','1H\nJD','XX','LL','DD','QQ','DL','GL','HZ',
'XH\nLL','NB','SS','GG','CD','XS\nBN'])
.add_yaxis('各门店电网投诉率',
data_y_0,
label_opts=opts.LabelOpts(formatter=JsCode("function (params) {return params.value[1] + '%'}")),
is_symbol_show=True,
areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
# markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='average', name='均值'),
# opts.MarkPointItem(type_='max', name='最大值'),
# opts.MarkPointItem(type_='min', name='最小值')],
# symbol_size=50)
)
.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts={"interval":"0"}), # 设置x轴标签旋转角度
yaxis_opts=opts.AxisOpts(name='',position='left'),
title_opts=opts.TitleOpts(title='电网公关分析',subtitle='目标:<0.6%'))
)
return line
def line_gongguan2():
month = ['1月', '2月', '3月', '4月', '5月', '6月']
data_y = ['0.75%','0.57%','1.39%','1.25%','0.74%','1.10%']
data_y1 = ['0.6%','0.6%','0.6%','0.6%','0.6%','0.6%']
data_y_0 = [float(x.strip('%')) for x in data_y]
data_y_2 = [float(x.strip('%')) for x in data_y1]
line = (
Line(init_opts=opts.InitOpts(theme=ThemeType.DARK,chart_id=2))
.add_xaxis(month)
.add_yaxis('1-6月各月电网投诉率',
data_y_0,
label_opts=opts.LabelOpts(formatter=JsCode("function (params) {return params.value[1] + '%'}")),
is_smooth=True,
)
.add_yaxis('目标',data_y_2,label_opts=opts.LabelOpts(formatter=JsCode("function (params) {return params.value[1] + '%'}")),
is_symbol_show=False)
.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts={"interval":"0"}), # 设置x轴标签旋转角度
title_opts=opts.TitleOpts(title='电网公关分析',subtitle='目标:<0.6%'))
)
return line
def page_layout():
page = Page(layout=Page.DraggablePageLayout) # 可拖动布局
# page = Page(layout=Page.SimplePageLayout) # 简单布局
page.add(
# line_markpoint('投诉率',['19.2%','11.7%','12.57%','20.21%','11.43%','9.8%','10.3%']),
line_gongguan(),
line_gongguan2()
)
page.render("test.html")
Page.save_resize_html("test.html",
cfg_file=r"C:\Users\lenovo\downloads\chart_config1.json",
dest="my_test.html")
page_layout()
最后完成的图如下