第一種:官網提供的方法(tooltip + 定時器 方式)
option = { title: { text: '餅圖程序調用高亮示例', left: 'center' }, tooltip: { trigger: 'item', formatter: '{a} <br/>{b} : {c} ({d}%)' }, legend: { orient: 'vertical', left: 'left', data: ['直接訪問', '郵件營銷', '聯盟廣告', '視頻廣告', '搜索引擎'] }, series: [ { name: '訪問來源', type: 'pie', radius: '55%', center: ['50%', '60%'], data: [ {value: 335, name: '直接訪問'}, {value: 310, name: '郵件營銷'}, {value: 234, name: '聯盟廣告'}, {value: 135, name: '視頻廣告'}, {value: 1548, name: '搜索引擎'} ], emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }; app.currentIndex = -1; setInterval(function () { var dataLen = option.series[0].data.length; // 取消之前高亮的圖形 myChart.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: app.currentIndex }); app.currentIndex = (app.currentIndex + 1) % dataLen; // 高亮當前圖形 myChart.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: app.currentIndex }); // 顯示 tooltip myChart.dispatchAction({ type: 'showTip', seriesIndex: 0, dataIndex: app.currentIndex }); }, 1000);
第二種:echarts-auto-tooltip插件方式,echarts-auto-tooltip下載 提取碼:276j;或者git地址:https://github.com/liuyishiforever/echarts-auto-tooltip/blob/master/demo.html。轉載至https://blog.csdn.net/qq_18344305/article/details/86064780。
需要注意的是,如果Echarts的數據用的是series里面的data,那么直接使用該插件即可。如果使用的是dataset,
[ ['product', '數量', '占比'], ["山東", "104", "19%"], ["山西", "86", "43%"], ["內蒙", "30", "4%"] ]
這種格式的data的話,在第70行左右需要改動一下:
原代碼:dataLen = series[seriesIndex].data.length;
修改之后:
if(options.dataType=='series'){ dataLen = series[seriesIndex].data.length; }else{ dataLen = chartOption.dataset.source.length-1; }
使用方法:
var echart_demo= echarts.init(document.getElementById('id'));
var option = {//具體內容不在此贅述}
tools.loopShowTooltip(echart_demo, option, {loopSeries: true,interval:6000});
備注:使用該插件,請配置Echarts中的empasis屬性