在Python中使用Pyecharts绘制BI大屏

做一个面积图和折线图

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()

最后完成的图如下
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

White_Mountain

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值