echart折线图如何让悬浮框出现在光标的左侧?
时间: 2023-11-16 08:12:28 浏览: 42
要让 ECharts 折线图中的悬浮框出现在光标的左侧,可以通过设置 tooltip 的 position 属性来实现。具体来说,可以将 position 的值设置为 `'top'`,并在此基础上再通过设置 axisPointer 的 type 属性为 `'cross'`,并将 label 的 position 属性设置为 `'left'` 来实现。示例代码如下:
```
option = {
tooltip: {
trigger: 'axis',
position: 'top',
axisPointer: {
type: 'cross'
},
formatter: '{b} : {c}'
},
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'line'
}]
};
```
在上面的代码中,我们通过设置 tooltip 的 position 属性为 `'top'`,并将 axisPointer 的 type 属性设置为 `'cross'`,来让悬浮框出现在光标的上方。同时,我们还将 label 的 position 属性设置为 `'left'`,来让悬浮框的标签在光标的左侧。