pyecharts 坐标名鼠标悬停展示
时间: 2023-07-05 16:09:14 浏览: 125
使用 Pyecharts 可以通过设置 tooltip 来实现鼠标悬停展示坐标名。
具体方法如下:
1. 导入需要的模块:
```python
from pyecharts.charts import Line
from pyecharts import options as opts
```
2. 创建一个 Line 类,并设置 x、y 坐标轴的数据:
```python
line = Line()
line.add_xaxis(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])
line.add_yaxis('Sales', [100, 200, 300, 400, 500, 600])
```
3. 设置 tooltip:
```python
line.set_series_opts(
tooltip_opts=opts.TooltipOpts(
trigger="axis", # 触发类型为坐标轴
axis_pointer_type="cross", # 指示器类型为十字准星指示器
formatter="{a} <br/>{b}: {c}", # tooltip 格式
)
)
```
其中,`trigger` 表示触发类型,这里设置为坐标轴;`axis_pointer_type` 表示指示器类型,这里设置为十字准星指示器;`formatter` 表示 tooltip 的格式,`{a}` 表示系列名称,`{b}` 表示 x 轴对应的值,`{c}` 表示 y 轴对应的值。
4. 渲染图表:
```python
line.render("line.html")
```
完整代码如下:
```python
from pyecharts.charts import Line
from pyecharts import options as opts
line = Line()
line.add_xaxis(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])
line.add_yaxis('Sales', [100, 200, 300, 400, 500, 600])
line.set_series_opts(
tooltip_opts=opts.TooltipOpts(
trigger="axis",
axis_pointer_type="cross",
formatter="{a} <br/>{b}: {c}",
)
)
line.render("line.html")
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)