vue结合Echarts实现点击高亮效果的示例

前端之家收集整理的这篇文章主要介绍了vue结合Echarts实现点击高亮效果的示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

@H_403_0@本文主要介绍如何在vue中使用Echarts实现点击高亮效果


@H_4030@

1、首先看一下官方网站上的介绍:


@H
403_0@<a rel="external nofollow" target="blank" href="http://echarts.baidu.com/api.html#action.graph.focusNodeAdjacency"&gt;http://echarts.baidu.com/api.html#action.graph.focusNodeAdjacency


@H
403_0@


@H_403_0@


@H_403_0@

2、在初始化的时候绑定这两个事件。需要绑定的事件是鼠标的点击事件和右键点击事件。


<div class="jb51code">
<pre class="brush:xhtml;">
mounted: function () {
let that = this;
let myChart = this.$echarts.init(document.getElementById('myChart'));
myChart.on('click',function (params) {
console.log(params);
//点击高亮
that.myChart.dispatchAction({
type: 'focusNodeAdjacency',// 使用 dataIndex 来定位节点。
dataIndex: params.dataIndex
});
if (params.dataType == 'edge') {
that.handleClick(params);
} else if (params.dataType == 'node') {
if (that.firstNode == '') {
that.firstNode = params.name;
} else {
that.secondNode = params.name;
}
}
});
//取消右键的弹出菜单
document.oncontextmenu = function () {
return false;
};
//右键取消高亮
myChart.on('contextmenu',function (params) {
console.log(params);
that.myChart.dispatchAction({
type: 'unfocusNodeAdjacency',// 使用 seriesId 或 seriesIndex 或 seriesName 来定位 series.
seriesIndex: params.seriesIndex,})
});
that.myChart = myChart;
that.drawLine();
},

@H_403_0@运行效果如下:

@H_403_0@

@H_403_0@

@H_403_0@以上这篇vue结合Echarts实现点击高亮效果的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

猜你在找的Vue相关文章