from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
# 创建一个折线图
line = Line()
# 添加数据
line.add_xaxis(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
line.add_yaxis('Sales', [120, 200, 150, 80, 70, 110, 130])
# 设置图表样式和配置项
line.set_global_opts(
title_opts=opts.TitleOpts(title="Sales Trend"),
xaxis_opts=opts.AxisOpts(name="Day"),
yaxis_opts=opts.AxisOpts(name="Sales"),
toolbox_opts=opts.ToolboxOpts(),
legend_opts=opts.LegendOpts(is_show=True),
# 添加resize方法,让图表随着窗口缩放变得顺滑
js_host="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.min.js",
js_callback=JsCode("chart.on('finished', function(){chart.resize();});"),
)
# 渲染图表
line.render_notebook()
ECharts更改JS默认生成地址
最新推荐文章于 2024-11-11 19:29:13 发布