Python3 得 Pyecharts 制作 Gauge(儀表盤) 時需要使用得設置參數和常用模板案例,可根據實際情況對案例中得內容進行調整即可。
Demo自定義儀表盤from pyecharts import options as optsfrom pyecharts.charts import Gaugec = ( Gauge() .add( "指示器", [("完成比率", 75.5)], radius="80%", # 設置比例大小 min_=0,max_= 200, # 設置起始、終止刻度 title_label_opts=opts.LabelOpts( font_size=20, color="black", font_family="Microsoft YaHei" # 設置字體、顏色、大小 ), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts( color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30 # 設置區間顏色、儀表寬度 ) ), ) .set_global_opts( title_opts=opts.TitleOpts( title="自定義儀表盤" ), legend_opts=opts.LegendOpts( is_show=False ), )# .render("自定義儀表盤.html"))c.render_notebook()
Gauge:儀表盤基本設置
class Gauge( # 初始化配置項,參考 `global_options.InitOpts` init_opts: opts.InitOpts = opts.InitOpts())
數據選項設置
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, # 儀表盤刻度是否是順時針增長。 is_clock_wise: bool = True, # 輪盤內標題文本項標簽配置項,參考 `chart_options.GaugeTitleOpts` title_label_opts: types.GaugeTitle = opts.GaugeTitleOpts(), # 輪盤內數據項標簽配置項,參考 `chart_options.GaugeDetailOpts` detail_label_opts: types.GaugeDetail = opts.GaugeDetailOpts(formatter="{value}%"), # 儀表盤指針配置項目,參考 `chart_options.GaugePointerOpts` pointer: types.GaugePointer = opts.GaugePointerOpts(), # 提示框組件配置項,參考 `series_options.TooltipOpts` tooltip_opts: Union[opts.TooltipOpts, dict, None] = None, # 圖元樣式配置項,參考 `series_options.ItemStyleOpts` itemstyle_opts: Union[opts.ItemStyleOpts, dict, None] = None,)
儀表盤數據標題配置項
class GaugeTitleOpts()
儀表盤數據內容配置項
class GaugeDetailOpts( # 是否顯示詳情。 is_show: bool = True, # 文字塊背景色。 # 可以是直接得顏色值,例如:'#123234', 'red', 'rgba(0,23,11,0.3)'。 background_color: str = "transparent", # 文字塊邊框寬度。 border_width: Numeric = 0, # 文字塊邊框顏色。 border_color: str = "transparent", # 相對于儀表盤中心得偏移位置,數組第壹項是水平方向得偏移,第二項是垂直方向得偏移。 # 可以是可能嗎?得數值,也可以是相對于儀表盤半徑得百分比。 offset_center: Sequence = [0, "-40%"], # 格式化函數或者字符串 formatter: Optional[JSFunc] = None, # 文字得顏色。 color: str = "auto", # 文字字體得風格。可選:'normal','italic','oblique' font_style: str = "normal", # 文字字體得粗細。可選:'normal','bold','bolder', 'lighter', 100 | 200 | 300 | 400... font_weight: str = "normal", # 文字得字體系列。還可以是 'serif' , 'monospace', 'Arial', 'Courier New', 'Microsoft YaHei', ... font_family: str = "sans-serif", # 文字得字體大小 font_size: Numeric = 15, # 文字塊得圓角。 border_radius: Numeric = 0, # 文字塊得內邊距。例如: # padding: [3, 4, 5, 6]:表示 [上, 右, 下, 左] 得邊距。 # padding: 4:表示 padding: [4, 4, 4, 4]。 # padding: [3, 4]:表示 padding: [3, 4, 3, 4]。 # 注意,文字塊得 width 和 height 指定得是內容高寬,不包含 padding。 padding: Numeric = 0, # 文字塊得背景陰影顏色。 shadow_color: Optional[str] = "transparent", # 文字塊得背景陰影長度。 shadow_blur: Optional[Numeric] = 0, # 文字塊得背景陰影 X 偏移。 shadow_offset_x: Numeric = 0, # 文字塊得背景陰影 Y 偏移。 shadow_offset_y: Numeric = 0,)
儀表盤指針配置項
class GaugePointerOpts( # 是否顯示指針。 is_show: bool = True, # 指針長度,可以是可能嗎?數值,也可以是相對于半徑得半分比。 length: Union[str, Numeric] = "80%", # 指針寬度。 width: Numeric = 8,)