網(wǎng)站首頁 編程語言 正文
pyecharts顯示數(shù)據(jù)為百分比的柱狀圖
pyecharts是做數(shù)據(jù)分析的好幫手,柱狀圖比較簡單,網(wǎng)站例子不夠多,一般柱狀圖就是直接傳兩組數(shù)據(jù)就搞掂了,如果想要顯示數(shù)據(jù)為百分比,比如下圖例子。
需要做兩處調(diào)整。
1、Y軸內(nèi)容
2、標簽內(nèi)容
查了文檔,都是修改opts.LabelOpts 。
做了個例子,供大家參考
# encoding: utf-8
"""
@author: seakingx
@contact: hndm@qq.com
@version: 1.0
@file: doex.py
@time: 2020/3/27 0019 09:39
說明 建立百分比的柱狀圖
"""
from pyecharts.charts import Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType
def create_bar(bar_dict):
# 建立百分比的柱狀圖
bar_item = bar_dict['item']
bar_head = bar_dict['head']
bar_data = bar_dict['data']
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis(bar_item)
.set_global_opts(title_opts=opts.TitleOpts(title="銷售情況", subtitle="占比情況"))
)
for i in range(len(bar_head)):
bar.add_yaxis(bar_head[i], bar_data[i], label_opts=opts.LabelOpts(formatter="{c} %"))
bar.set_global_opts(
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter="{value} %"), interval=10))
return bar
def get_data_dict():
# 這里獲取要顯示的數(shù)據(jù) , 可以改成連接數(shù)據(jù)庫
data_a = [round(n*100,2) for n in [0.2155, 0.423, 0.351, 0.4422, 0.651, 0.722]]
data_b = [round(n*100,2) for n in [0.1233, 0.231, 0.4522, 0.5612, 0.6667, 0.745]]
pdt_list = ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
data_dict= {'data':[data_a,data_b], 'head':['商家甲','商家乙'], 'item':pdt_list}
return data_dict
if __name__=="__main__":
data = get_data_dict()
bar = create_bar(data)
bar.render()
Echarts之顯示百分比問題
對于使用echarts要顯示百分比,要改兩個地方,第一個地方時坐標軸顯示為百分比的格式,第二個是讓值以百分比的形式顯示,如50,在圖上面顯示為50%。
yAxis: [ ?
? ? ? ? { ?
? ? ? ? ? ? type: 'value', ?
? ? ? ? ? ? axisLabel: { ?
? ? ? ? ? ? ? ? ? show: true, ?
? ? ? ? ? ? ? ? ? interval: 'auto', ?
? ? ? ? ? ? ? ? ? formatter: '{value} %' ?
? ? ? ? ? ? ? ? }, ?
? ? ? ? ? ? show: true ?
? ? ? ? } ?
? ? ], ?
第二個是改series
? itemStyle: { ?
? ? ? ? ? ? ? ? normal: { ?
? ? ? ? ? ? ? ? ? ? label: { ?
? ? ? ? ? ? ? ? ? ? ? ? show: true, ?
? ? ? ? ? ? ? ? ? ? ? ? position: 'top', ?
? ? ? ? ? ? ? ? ? ? ? ? formatter: '{b}\n{c}%' ?
? ? ? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? ? ? } ?
? ? ? ? ? ? }, ?
原文鏈接:https://blog.csdn.net/seakingx/article/details/105135110
相關(guān)推薦
- 2022-09-26 nodemon安裝在開發(fā)環(huán)境(非全局安裝)報錯解決【兩種方式】
- 2022-04-07 WPF常用控件用法及介紹_實用技巧
- 2022-12-23 Android入門之彈出式對話框的實現(xiàn)_Android
- 2023-04-14 React超詳細講述Fiber的使用_React
- 2022-11-01 AndroidView與Compose框架交互實現(xiàn)介紹_Android
- 2022-08-02 使用shell讀取ini文件方法步驟_linux shell
- 2022-03-14 npm 更改為淘寶鏡像的方法
- 2022-07-16 git查看和修改用戶名和郵箱
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支