echarts 图表的内容的轮播


第一种:官网提供的方法(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属性

 

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM