Python笔记:制作和自定义仪表盘

亡梦爱人 提交于 2020-07-29 09:21:42

        仪表盘可用于表示(达成率)完成率等指标的数据呈现。

具体操作如下:

# 先安装pyecharts库和Gauge库(最好是安装最新版的)
pip install pyecharts
pip install Gauge
#导入相关模块
import pyecharts.options as opts
from pyecharts.charts import Gauge
Gaug_1=(
    #创建仪表盘对象,并设置大小,也可以不设置,直接使用默认大小即可
    Gauge(init_opts=opts.InitOpts(width="800px", height="400px"))
    #设置数据系列名称及数据
    .add(series_name="达成率", data_pair=[["达成率", 96.8]])
    .set_global_opts(
        # 设置图表标题及位置
        title_opts=opts.TitleOpts(title="蔬菜部门销售进度",pos_left="center"),
        # 设置不显示图例,饼图不建议使用图例,不方便读图
        legend_opts=opts.LegendOpts(is_show=False),
        #设置提示框数据标签显示格式
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"),
    )
    #通过render()方法将仪表盘渲染为html
#     .render("gauge.html")
)
Gaug_1.render_notebook()

给仪表盘各区间自定义一个颜色:

Gaug_1=(
    Gauge(init_opts=opts.InitOpts(width="800px", height="400px"))
    .add(series_name="完成率", data_pair=[["达成率", 66.6]],
         #设置仪表盘颜色
         axisline_opts=opts.AxisLineOpts(
            linestyle_opts=opts.LineStyleOpts(
                color=[(0.6, "#fd666d"), (0.8, "#FFD700"),(1, "#3CB371")], width=30)))
    .set_global_opts(
        title_opts=opts.TitleOpts(title="水果部门销售业绩",pos_left="center"),
        legend_opts=opts.LegendOpts(is_show=False),
        tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"),
    )
#     .render("gauge.html")
)
Gaug_1.render_notebook()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!