1.导入模块
- Bar
- Timeline
- LabelOpts
- ThemeType
from pyecharts.charts import Bar,Timeline
from pyecharts.options import LabelOpts
from pyecharts.globals import ThemeType
2.数据创建
bar1 = Bar()
bar1.add_xaxis(["中国","美国","小日本"])
bar1.add_yaxis("GDP",[30,20,5],label_opts=LabelOpts(position="right"))
bar1.reversal_axis()
bar2 = Bar()
bar2.add_xaxis(["中国","美国","小日本"])
bar2.add_yaxis("GDP",[40,20,4],label_opts=LabelOpts(position="right"))
bar2.reversal_axis()
bar3 = Bar()
bar3.add_xaxis(["中国","美国","小日本"])
bar3.add_yaxis("GDP",[88,30,2],label_opts=LabelOpts(position="right"))
bar3.reversal_axis()
3.构建时间线对象(含主题颜色)
# 构建时间线对象
timeline = Timeline({"theme": ThemeType.LIGHT})
# 在时间线内添加数据
timeline.add(bar1,"点1")
timeline.add(bar2,"点2")
timeline.add(bar3,"点3")
4.设置自动播放
# 设置自动播报
timeline.add_schema(
play_interval=1000,
is_timeline_show=True,
is_auto_play=True,
is_loop_play=True
)
5.绘图
# 通过时间线进行绘图
timeline.render("基础时间线.html")