【无标题】echarts饼图自动循环高亮

<!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>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现echarts自动播放效果,可以使用echarts提供的动画和定时器功能。首先,确保你已经引入了echarts库。 然后,使用以下步骤来实现自动播放效果: 1. 创建一个echarts实例: this.pieChart = this.$echarts.init(document.getElementById(this.id)); 2. 定义初始的数据: var data = [ { value: 335, name: '数据1' }, { value: 310, name: '数据2' }, { value: 234, name: '数据3' }, { value: 135, name: '数据4' }, { value: 1548, name: '数据5' } ]; 3. 设置的配置项,包括自动播放的参数: var option = { series: [ { type: 'pie', radius: ['50%', '70%'], animation: true, // 开启动画效果 animationType: 'scale', // 设置动画类型 animationEasing: 'elasticOut', // 设置动画缓动效果 animationDelay: function (idx) { // 设置动画延迟时间 return idx * 200; }, data: data } ] }; 4. 在echarts实例中设置配置项: this.pieChart.setOption(option); 5. 使用定时器来实现自动播放效果: var currentIndex = -1; setInterval(function () { var dataLen = option.series.data.length; // 取消之前高亮形 this.pieChart.dispatchAction({ type: 'downplay', seriesIndex: 0, dataIndex: currentIndex }); currentIndex = (currentIndex + 1) % dataLen; // 高亮当前形 this.pieChart.dispatchAction({ type: 'highlight', seriesIndex: 0, dataIndex: currentIndex }); // 显示提示框 this.pieChart.dispatchAction({ type: 'showTip', seriesIndex: 0, dataIndex: currentIndex }); }, 2000); 通过以上步骤,你就可以实现echarts自动播放效果了。定时器每隔2秒钟切换到下一个数据,并高亮该数据的形,并显示提示框。你可以根据需要调整定时器的时间间隔和的数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值