// 使用刚指定的配置项和数据显示图表。
myChart2.setOption(option);
//设置默认选中高亮部分
let index = 0;
myChart2.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
});
// 当鼠标移入时,如果不是第一项,则把当前项置为选中,如果是第一项,则设置第一项为当前项
myChart2.on('mouseover', function(e) {
myChart2.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: 0
});
if (e.dataIndex != index) {
myChart2.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: index
});
}
if (e.dataIndex == 0) {
myChart2.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
});
}
});
//当鼠标离开时,把当前项置为选中
myChart2.on('mouseout', function(e) {
index = e.dataIndex;
myChart2.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
});
});
myChart2.dispatchAction({
type: 'showTip',
seriesIndex: 0, // 显示第几个series
dataIndex: 0 // 显示第几个数据
});
