【问题标题】:Make the x-axis values clickable in eCharts使 x 轴值在 eCharts 中可点击
【发布时间】:2021-01-06 12:02:56
【问题描述】:

我在我的项目中使用 eCharts,需要使它们可点击,以便我可以从那里调用函数。有什么办法吗?

在上图中,我应该可以单击 X 轴中的任何 RTVP... 数字来触发功能。

【问题讨论】:

    标签: angularjs echarts apache-echarts


    【解决方案1】:

    是的,你只需要就是爱来添加事件处理程序。

      myChart.on('click', 'series', (e) => {
        console.log(e);
      })
    

    查看实时示例:

    var myChart = echarts.init(document.getElementById('chart'));
    
    var option = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      grid: {
        top: 10,
        left: '2%',
        right: '2%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: [{
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        axisTick: {
          alignWithLabel: true
        }
      }],
      yAxis: [{
        type: 'value',
        axisTick: {
          show: false
        }
      }],
      series: [{
        name: 'pageA',
        type: 'bar',
        data: [79, 52, 200, 334, 390, 330, 220],
        color: 'steelBlue'
      }]
    };
    
    myChart.setOption(option);
    
    // Here you can exec any function under handler,
    // OR
    // _
    myChart.on('click', 'series', (e) => {
        console.log(e.name)
     })
    <script src="https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js"></script>
    <div id="chart" style="width: 600px;height:400px;"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多