当前位置:网站首页>Echart饼图添加轮播效果
Echart饼图添加轮播效果
2022-07-31 09:26:00 【一只成序源】
Echart饼图轮播效果
关键代码如下,传入饼图数据的长度,以及饼图echart对象即可完成饼图的轮播,代码如下:
/**
*
* @param pieDataLength 饼图数据长度
* @param ec 饼图echart对象
* @param time 轮播时间
*/
export function pipeAnimation(pieDataLength: number, ec: any,time:number) {
let timer = null;
if (pieDataLength < 2) {
setTimeout(() => {
ec.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
})
})
return;
}
let curIndex = 0;
if (timer) {
clearInterval(timer)
}
timer = setInterval(() => {
let dataLen = pieDataLength;
ec.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: curIndex });
curIndex = (curIndex + 1) % dataLen
ec.dispatchAction({
type: 'highlight', seriesIndex: 0, dataIndex: curIndex
});
}, time);
ec.on('mouseover', function (param) {
clearInterval(timer)
ec.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: curIndex
})
ec.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: param.dataIndex
})
curIndex = param.dataIndex;
})
ec.on('mouseout', function (param) {
curIndex = param.dataIndex;
if (timer) {
clearInterval(timer)
}
timer = setInterval(() => {
let dataLen = pieDataLength;
ec.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: curIndex });
curIndex = (curIndex + 1) % dataLen
ec.dispatchAction({
type: 'highlight', seriesIndex: 0, dataIndex: curIndex
});
}, time);
})
}
饼图图的高亮,隐藏关键代码设置,通过监听鼠标移入移出时间控制即可。导出成一个公用方法,使用时直接调用,传入数据长度及ecahrt图形对象即可。简单操作
边栏推荐
猜你喜欢
随机推荐
(C语言基础)原样输入输出
Modular specifications
Progressive Web App(PWA)
Kotlin入门介绍篇
VMware下安装win10
来n遍剑指--05. 替换空格
JSP exception对象简介说明
MySQL (2)
第八章 、接口
Are postgresql range queries faster than index queries?
spark过滤器
canvas粒子变幻各种形状js特效
win10镜像下载
Binary tree search and backtracking problem (leetcode)
2022 Hangzhou Electric Cup Super League 3
Linux 创建mysql数据库并创建账号密码
文件的逻辑结构与物理结构的对比与区别
qt在不同的线程中传递自定义结构体参数
jupyter notebook初使用
MySQL 排序