stack类似于给柱状图一个标记,category_gap:设置Bar之间间隔,默认20%。
c = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
.add_xaxis([1,2,3,4,5])
.add_yaxis("product1",list2,stack="stack1",category_gap="50%")
.add_yaxis("product2",list3,stack="stack1",category_gap="50%")
.set_series_opts(
label_opts=opts.LabelOpts(
position="right",
formatter=JsCode(
"function(x){return Number(x.data.percent * 100).toFixed() + '%';}"
)
)
)
)
c = (
Bar()
.add_xaxis(
[
"名字很长的x轴标签1",
"名字很长的x轴标签2",
"名字很长的x轴标签3",
"名字很长的x轴标签4",
"名字很长的x轴标签5",
"名字很长的x轴标签6",
]
)
.add_yaxis("storeA",[10,20,30,40,50,40])
.add_yaxis("storeB",[20,10,40,30,40,50])
.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
title_opts=opts.TitleOpts(title="Bar_旋转x轴标签",subtitle="解决标签名字过长问题")
)
).render_notebook()
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-Brush示例", subtitle="我是副标题"),
brush_opts=opts.BrushOpts(),
)
.render("bar_with_brush.html")
)
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis('storeA',Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title='barr-DataZoom(slider)'),
datazoom_opts=opts.DataZoomOpts()
)
).render_notebook()
c = (
Bar()
.add_xaxis(Faker.days_attrs)
.add_yaxis('商家A',Faker.days_values,color=Faker.rand_color())
.set_global_opts(
title_opts=opts.TitleOpts(title="bar-Datazoom-slider"),
datazoom_opts=opts.DataZoomOpts(orient='vertical')
)
.render_notebook()
)
set_global_opts(
legend_opts=opts.LegendOpts(is_show=True)
)
可以进行折线图、柱状图、堆叠等的转换
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.set_global_opts(
title_opts=opts.TitleOpts(title="Bar-显示 ToolBox"),
toolbox_opts=opts.ToolboxOpts(),
legend_opts=opts.LegendOpts(is_show=False),
)
.render("bar_toolbox.html")
)
bar = (
Bar(init_opts=opts.InitOpts(width="1000px",height="800px"))
.add_xaxis(x_data)
.add_yaxis(
series_name="蒸发量",
yaxis_data=[
2.0,
4.9,
7.0,
23.2,
25.6,
76.7,
135.6,
162.2,
32.6,
20.0,
6.4,
3.3,
],
label_opts=opts.LabelOpts(is_show=False)
)
.add_yaxis(
series_name="降水量",
yaxis_data=[
2.6,
5.9,
9.0,
26.4,
28.7,
70.7,
175.6,
182.2,
48.7,
18.8,
6.0,
2.3,
],
label_opts=opts.LabelOpts(is_show=True)
)
.extend_axis(
yaxis=opts.AxisOpts(
name="温度",type_="value",min_=0,max_=25,interval=5,axislabel_opts=opts.LabelOpts(formatter="{value} C")
)
)
set_global_opts(
title_opts=opts.TitleOpts(title="bar-xy轴名称"),
yaxis_opts=opts.AxisOpts(name="我是Y轴"),
xaxis_opts=opts.AxisOpts(name="我是x轴")
)
set_global_opts(
yaxis_opts=opts.AxisOpts(
axistick_opts=opts.AxisTickOpts(is_show=True),
splitline_opts=opts.SplitLineOpts(is_show=True)
)
)
set_global_opts(
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(formatter='{value}/月'))
)
set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_='max',name='最大值'),
opts.MarkPointItem(type_='min',name='最小值'),
opts.MarkPointItem(type_='average',name='平均值')
]
)
)
set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[
opts.MarkLineItem(type_='min',name='最小值'),
opts.MarkLineItem(type_='max',name='最大值'),
opts.MarkLineItem(type_='average',name='平均值')
]
)
)
def Bar_is_selected():
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis('A',Faker.values())
.add_yaxis('B',Faker.values(),is_selected=False) #默认不显示,可选
.set_global_opts(
title_opts=opts.TitleOpts(title='选择显示series')
)
).render_notebook()
return c
def Bar_reversal_axis():
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis('A',Faker.values())
.add_yaxis('B',Faker.values())
.reversal_axis()
#设置标签值显示位置
.set_series_opts(label_opts=opts.LabelOpts(position='right'))
).render_notebook()
return c
x,y=Faker.choose(),Faker.values()
c = (
Bar()
.add_xaxis(x)
.add_yaxis('A',y,
markpoint_opts=opts.MarkPointOpts(
data=[opts.MarkPointItem(name='自定义标记点',coord=[x[2],y[2]],value=y[2])
]
)
)
.add_yaxis('B',Faker.values())
).render_notebook()
def Bar_markline_custom():
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis("A",Faker.values())
.add_yaxis('B',Faker.values())
.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markline_opts=opts.MarkLineOpts(
data=[opts.MarkLineItem(y=50,name='yAxis=50')]
)
).render_notebook()
)
return c
c = (
Bar()
.add_xaxis(Faker.choose())
.add_yaxis('A',Faker.values(),color=Faker.rand_color())
.set_global_opts(
title_opts=opts.TitleOpts(title='bar-Datazoom(inside)'),
#把需要的效果放在列表里(缩放+x轴拖动)
datazoom_opts=[opts.DataZoomOpts(),opts.DataZoomOpts(type_='inside')]
)
)