当前位置:网站首页>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图形对象即可。简单操作
边栏推荐
猜你喜欢
随机推荐
内联元素居中
零代码工具推荐 八爪鱼采集器
来n遍剑指--06. 从尾到头打印链表
Kotlin—基本语法(一)
刷题《剑指Offer》day07
让动画每次重复前都有延迟
刷题《剑指Offer》day05
Scala基础【seq、set、map、元组、WordCount、队列、并行】
【NLP】Transformer理论解读
自定义v-drag指令(横向拖拽滚动)
js right dot single page scrolling introduction page
qt在不同的线程中传递自定义结构体参数
开放麒麟 openKylin 自动化开发者平台正式发布
浏览器使用占比js雷达图
【TCP/IP】网络模型
vue element form表单规则校验 点击提交后直接报数据库错误,没有显示错误信息
一次Spark SQL线上问题排查和定位
期刊投递时的 Late News Submission 是什么
loadrunner脚本--添加事务
第二十二课,实例化(instancing)









