<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
#main{
width: 800px;
height:600px;
border: 1px solid #cccccc;
}
</style>
<script src="js/echarts-4.1.0.js"></script>
</head>
<body>
<div id="main"></div>
<script>
let timer = null
let myChart = echarts.init(document.getElementById('main'),'vintage');
myChart.setOption({
itemStyle: {
emphasis: {
shadowBlur: 200,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
series : [
{
name: '访问来源',
type: 'pie',
radius: ['45%', '85%'],
data: [
{value:235, name:'视频广告'},
{value:274, name:'联盟广告'},
{value:310, name:'邮件营销'},
{value:335, name:'直接访问'},
{value:400, name:'搜索引擎'}
]
}
]
});
triggerToolTip(myChart)
function triggerToolTip(myChart) {
let index = 0
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
})
timer = setInterval(function() {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: [0, 1, 2, 3, 4]
})
index++
if (index > 4) {
index = 0
}
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: index
})
}, 3000)
myChart.on('mouseover', e => {
if (e.dataIndex !== index) {
myChart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: index
})
}
})
myChart.on('mouseout', e => {
index = e.dataIndex
myChart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: e.dataIndex
})
})
}
</script>
</body>
</html>
【无标题】echarts饼图自动循环高亮
最新推荐文章于 2024-05-14 16:17:58 发布