前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Echarts——如何默认选中图表并显示tooltip

Echarts——如何默认选中图表并显示tooltip

原创
作者头像
思索
发布2024-06-24 23:51:46
1400
发布2024-06-24 23:51:46

前言

action: action

event : event

event and action : 参考资料

code : 实现预览地址

内容

很简单借助于dispatchAction来触发事件;

代码语言:javascript
复制
import * as echarts from 'echarts';



var chartDom = document.getElementById('main');

var myChart = echarts.init(chartDom);

var option;



option = {

  tooltip: {

    trigger: 'axis',

    axisPointer: {

      type: 'shadow'

    }

  },

  legend: {},

  grid: {

    left: '3%',

    right: '4%',

    bottom: '3%',

    containLabel: true

  },

  xAxis: [

    {

      type: 'category',

      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']

    }

  ],

  yAxis: [

    {

      type: 'value'

    }

  ],

  series: [

    {

      name: 'Direct',

      type: 'bar',

      emphasis: {

        focus: 'series'

      },

      data: [320, 332, 301, 334, 390, 330, 320]

    },

    {

      name: 'Email',

      type: 'bar',

      stack: 'Ad',

      emphasis: {

        focus: 'series'

      },

      data: [120, 132, 101, 134, 90, 230, 210]

    },

    {

      name: 'Union Ads',

      type: 'bar',

      stack: 'Ad',

      emphasis: {

        focus: 'series'

      },

      data: [220, 182, 191, 234, 290, 330, 310]

    },

    {

      name: 'Video Ads',

      type: 'bar',

      stack: 'Ad',

      emphasis: {

        focus: 'series'

      },

      data: [150, 232, 201, 154, 190, 330, 410]

    },

    {

      name: 'Search Engine',

      type: 'bar',

      data: [862, 1018, 964, 1026, 1679, 1600, 1570],

      emphasis: {

        focus: 'series'

      },

      markLine: {

        lineStyle: {

          type: 'dashed'

        },

        data: [[{ type: 'min' }, { type: 'max' }]]

      }

    },

    {

      name: 'Baidu',

      type: 'bar',

      barWidth: 5,

      stack: 'Search Engine',

      emphasis: {

        focus: 'series'

      },

      data: [620, 732, 701, 734, 1090, 1130, 1120]

    },

    {

      name: 'Google',

      type: 'bar',

      stack: 'Search Engine',

      emphasis: {

        focus: 'series'

      },

      data: [120, 132, 101, 134, 290, 230, 220]

    },

    {

      name: 'Bing',

      type: 'bar',

      stack: 'Search Engine',

      emphasis: {

        focus: 'series'

      },

      data: [60, 72, 71, 74, 190, 130, 110]

    },

    {

      name: 'Others',

      type: 'bar',

      stack: 'Search Engine',

      emphasis: {

        focus: 'series'

      },

      data: [62, 82, 91, 84, 109, 110, 120]

    }

  ]

};



option && myChart.setOption(option);



setTimeout(function () {

  myChart.dispatchAction({

    type: 'highlight',

    seriesIndex: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],

    dataIndex: 1

  });

  myChart.dispatchAction({

    type: 'showTip',

    seriesIndex: 0,

    dataIndex: 1

  });

}, 1000);

实现效果

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 内容
    • 实现效果
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档