from pyecharts import options as opts from pyecharts.charts import Line import pandas as pd # 读取Excel文件 data = pd.read_excel('6004021055.xlsx') # 提取数据 week = data['week'] need = data['need'] # 创建折线图对象 line = Line() line.set_global_opts( xaxis_opts=opts.AxisOpts(name='week', split_number=18, interval=10), yaxis_opts=opts.AxisOpts(name='need', split_number=10, interval=10, axislabel_opts={"interval": 10}), title_opts=opts.TitleOpts(title='6004021055'), tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross") ) # 设置图例 legend_data = ['需求'] line.add_xaxis(week) line.add_yaxis(legend_data[0], need, is_smooth=True, label_opts=opts.LabelOpts(is_show=False)) # 显示中文标签 line.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top')) # 生成HTML文件 line.render('line_chart_6004021055.html')我这个代码中实现的效果里数据点上有没有对应数据显示出来
时间: 2024-04-17 21:25:30 浏览: 371
h5py_test.rar_.h5文件 h5py_h5文件读取_hdf_ruleq77_读取H5数据
你可以通过设置 `tooltip_opts` 中的 `formatter` 属性来自定义数据提示框的显示内容。下面是修改后的代码,只在鼠标悬停时显示数据:
```python
from pyecharts import options as opts
from pyecharts.charts import Line
import pandas as pd
# 读取Excel文件
data = pd.read_excel('6004021055.xlsx')
# 提取数据
week = data['week']
need = data['need']
# 创建折线图对象
line = Line()
line.set_global_opts(
xaxis_opts=opts.AxisOpts(name='week', split_number=18, interval=10),
yaxis_opts=opts.AxisOpts(name='need', split_number=10, interval=10, axislabel_opts={"interval": 10}),
title_opts=opts.TitleOpts(title='6004021055'),
tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross", formatter="{c}")
)
# 设置图例
legend_data = ['需求']
line.add_xaxis(week)
line.add_yaxis(legend_data[0], need, is_smooth=True, label_opts=opts.LabelOpts(is_show=False))
# 显示中文标签
line.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top'))
# 生成HTML文件
line.render('line_chart_6004021055.html')
```
这样修改后,生成的折线图上只有在鼠标悬停时才会显示数据,数据显示的内容是数据点对应的值。
阅读全文