from pyecharts.charts import Bar bar = Bar() #添加x轴数据 c = ( Bar() .add_xaxis(['苹果','橘子','梨','樱桃'])#添加x轴数据 .add_yaxis('金额',[10,5,8,17])#添加y轴数据 .render('fruit.html')#渲染数据 )
链式调用
pyecharts中所有的方法都支持链式调用。
1 2 3 4 5 6 7 8 9
from pyecharts.charts import Bar bar = Bar() #添加x轴数据 c = ( Bar() .add_xaxis(['苹果','橘子','梨','樱桃'])#添加x轴数据 .add_yaxis('金额',[10,5,8,17])#添加y轴数据 .render('fruit.html')#渲染数据 )
from pyecharts.charts import Bar from pyecharts import options as opts #导入配置项 from faker import Faker bar = Bar() #添加x轴数据 c = ( Bar(init_opts=opts.InitOpts(width='400px',height='300px',bg_color='#ccc')) .add_xaxis(Faker.choose()) .add_yaxis('金额',Faker.values()) ) c.render('faker1.html')
from pyecharts.charts import Bar from pyecharts import options as opts #导入配置项 from faker import Faker bar = Bar() #标题配置项 c = ( Bar() .add_xaxis(Faker.choose()) .add_yaxis('金额',Faker.values()) .set_global_opts( title_opts=opts.TitleOpts( title='商品价格', subtitle='项目', pos_left='20px', title_textstyle_opts=opts.TextStyleOpts( font_size=10 )
) ) ) c.render('faker2.html')
LegendOpts:图例配置项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
from pyecharts.charts import Bar from pyecharts import options as opts #导入配置项 from faker import Faker bar = Bar()