pyecharts更改柱状图每个柱的颜色
warning:
这篇文章距离上次修改已过989天,其中的内容可能已经有所变动。
from pyecharts.commons.utils import JsCode
value=[7.0,11.0,50.0,112.0]
color_function = """
function (params) {
if (params.value == 7.0)
return '#66CCCC';
else if (params.value ==11.0)
return '#CCCCFF';
else if (params.value ==50.0)
return '#FF6666';
else return '#CCFFCC';
}
"""
c_3 = (
Bar(init_opts=opts.InitOpts(width="800px",height="400px",))
.add_xaxis(['睡觉','说话','离开','学习'],)
.add_yaxis("",value,itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_function)))
.set_global_opts(
title_opts=opts.TitleOpts(title="国内疫情数据"),
legend_opts=opts.LegendOpts(pos_left="20%"),
datazoom_opts=opts.DataZoomOpts(type_="inside"),
)
)