关于插件echarts的一个问题

图片描述

这个是鼠标移进去的效果,但是我想打开页面的时候,就有一个默认为这样的!

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>ECharts</title>
  <!-- 引入 echarts.js -->
  <script src="echarts.js"></script>
</head>

<body>
  <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
  <div id="main" style="width: 335px;height:325px;"></div>
  <script type="text/javascript">
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));

    // 指定图表的配置项和数据

    option = {
      tooltip: {
        trigger: 'item'
      },
      series: [{
          name: '学校录取信息',
          type: 'pie',
          radius: ['45%', '70%'],
          avoidLabelOverlap: false,
          label: {
            normal: {
              show: false,
              position: 'center'
            },
            emphasis: {
              show: true,
              textStyle: {
                fontSize: '14',
                fontWeight: 'bold'
              }
            }
          },
          labelLine: {
            normal: {
              show: true
            }
          },
          data: [{
              value: 335,
              name: '直接访问'
            },
            {
              value: 310,
              name: '邮件营销'
            },
            {
              value: 234,
              name: '联盟广告'
            },
            {
              value: 135,
              name: '视频广告'
            },
            {
              value: 1548,
              name: '搜索引擎'
            }
          ]
        },
        {
          name: 'radial gradient',
          type: 'pie',
          radius: '70%',
          avoidLabelOverlap: false,
          itemStyle: {
            normal: {
              color: {
                type: 'radial',
                x: 0.5,
                y: 0.5,
                r: 0.5,
                colorStops: [{
                  offset: 0,
                  color: 'rgba(255,255,255,0)'
                }, {
                  offset: 0.55,
                  color: 'rgba(255,255,255,0.5)'
                }, {
                  offset: 0.65,
                  color: 'rgba(255,255,255,0.5)'
                }, {
                  offset: 0.95,
                  color: 'rgba(255,255,255,0)'
                }],
                globalCoord: false
              }
            }
          },
          silent: true,
          z: 999,
        }
      ]
    };

    var index = 0;//数据的第几个显示
//高亮图形
myChart.dispatchAction({
  type: 'highlight',
  seriesIndex: 0,
  dataIndex: index
});
// 显示 tooltip
myChart.dispatchAction({
  type: 'showTip',
  seriesIndex: 0,
  dataIndex: index
});
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);


  </script>
</body>

</html>
阅读 2.7k
2 个回答

不知道作者是否有尝试监听事件来进行操作。
不知道是想一直保持显示联盟广告还是其他交互,建议尝试在事件中进行相关处理。

myChart.on('mouseover', function (params,e) {
  if (params.name == '联盟广告') {
    console.log(params);
  }
});

可参考官方文档ECharts 中的事件和行为

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题