问题描述:
起始点的位置不对
python
from pyecharts.charts import Line
import pyecharts.options as opts
# 示例数据
x_data = [1,2,3,4,5]
y_data = ['1', '2', '3', '4', '5']
# 创建 Line 图表
line = Line()
line.add_xaxis(x_data)
line.add_yaxis("test", y_data)
line.set_global_opts(
xaxis_opts={"name": "X轴"},
yaxis_opts={"name": "Y轴"}
)
line.render("test.html")
问题解决:
通过网上的搜索查到,需要将y轴的数据变为字符型
python
from pyecharts.charts import Line
import pyecharts.options as opts
# 示例数据
x_data = ['1', '2', '3', '4', '5']
y_data = ['1', '2', '3', '4', '5']
# 创建 Line 图表
line = Line()
line.add_xaxis(x_data)
line.add_yaxis("test", y_data)
line.set_global_opts(
xaxis_opts={"name": "X轴"},
yaxis_opts={"name": "Y轴"}
)
line.render("test.html")