龙空技术网

pyecharts堆积百分比柱状图

繁梦溪 99

前言:

目前小伙伴们对“jsecharts柱状图”可能比较关心,各位老铁们都需要分析一些“jsecharts柱状图”的相关文章。那么小编也在网上网罗了一些对于“jsecharts柱状图””的相关资讯,希望咱们能喜欢,姐妹们快快来了解一下吧!

代码效果

Bar - Stack_bar_percent

代码

from pyecharts import options as optsfrom pyecharts.charts import Barfrom pyecharts.commons.utils import JsCodefrom pyecharts.globals import ThemeTypevalue2=value3=100list2 = [    {"value": value2*0.2, "percent": 0.2},    {"value": value2*0.3, "percent": 0.3},    {"value": value2*0.4, "percent": 0.4},    {"value": value2*0.9, "percent": 0.9},    {"value": value2*0.8, "percent": 0.8},]list3 = [    {"value": value3*0.8, "percent": 0.8},    {"value": value3*0.7, "percent": 0.7},    {"value": value3*0.6, "percent": 0.6},    {"value": value3*0.1, "percent": 0.1},    {"value": value3*0.2, "percent": 0.2},]bar=Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))bar.add_xaxis([2016, 2017, 2018, 2019, 2020])bar.add_yaxis("product1", list2, stack="stack1", category_gap="50%")bar.add_yaxis("product2", list3, stack="stack1", category_gap="50%")bar.set_series_opts(        label_opts=opts.LabelOpts(            position="right",            formatter=JsCode(                "function(x){return Number(x.data.percent * 100).toFixed() + '%';}"            ),        )    )bar.render_notebook()#在jupyter中直接显示bar.render("./html/stack_bar_percent.html")#保存为HTML文件

标签: #jsecharts柱状图