Pyecharts之儀表盤(Gauge)
from snapshot_selenium import snapshot as driver
from pyecharts import options as opts
from pyecharts.charts import Gauge
from pyecharts.render import make_snapshot
from pyecharts.globals import CurrentConfig,NotebookType
CurrentConfig.NOTEBOOK_TYPE=NotebookType.JUPYTER_LAB
一.基本概念
class pyecharts.charts.Gauge
class Gauge(
# 初始化配置項,參考 `global_options.InitOpts`
init_opts: opts.InitOpts = opts.InitOpts()
)
func pyecharts.charts.Gauge.add
def add(
# 系列名稱,用於 tooltip 的顯示,legend 的圖例篩選。
series_name: str,
# 系列數據項,格式為 [(key1, value1), (key2, value2)]
data_pair: Sequence,
# 是否選中圖例
is_selected: bool = True,
# 最小的數據值
min_: Numeric = 0,
# 最大的數據值
max_: Numeric = 100,
# 儀表盤平均分割段數
split_number: Numeric = 10,
# 儀表盤半徑,可以是相對於容器高寬中較小的一項的一半的百分比,也可以是絕對的數值。
radius: types.Union[types.Numeric, str] = "75%",
# 儀表盤起始角度。圓心 正右手側為0度,正上方為 90 度,正左手側為 180 度。
start_angle: Numeric = 225,
# 儀表盤結束角度。
end_angle: Numeric = -45,
# 輪盤內標題文本項標簽配置項,參考 `series_options.LabelOpts`
title_label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),
# 輪盤內數據項標簽配置項,參考 `series_options.LabelOpts`
detail_label_opts: Union[opts.LabelOpts, dict] = opts.LabelOpts(),
# 提示框組件配置項,參考 `series_options.TooltipOpts`
tooltip_opts: Union[opts.TooltipOpts, dict, None] = None,
# 圖元樣式配置項,參考 `series_options.ItemStyleOpts`
itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,
)
二.代碼示例
1.Gauge
g=(
Gauge(init_opts=opts.InitOpts(width="1000px",height="600px"))
.add(
series_name="業務指標",
data_pair=[("完成率",55.5),("未達標",20.4)]
)
.set_global_opts(
legend_opts=opts.LegendOpts(is_show=True),
tooltip_opts=opts.TooltipOpts(is_show=True,formatter="{a} <br/>{b}:{c}")
)
)
make_snapshot(driver,g.render("gauge.html"),"gauge.png")
g.load_javascript()
g.render_notebook()
from pyecharts import options as opts
from pyecharts.charts import Gauge
c = (
Gauge()
.add("", [("完成率", 66.6)],start_angle=-45,end_angle=-135)
.set_global_opts(title_opts=opts.TitleOpts(title="Gauge-基本示例"))
#.render("gauge_base.html")
)
#make_snapshot(driver,c.render("test.html"),"gauge.png")
c.load_javascript()
c.render_notebook()