繁体   English   中英

Echarts:如何在单击标题时调用自定义函数?

[英]Echarts : How to call custom function on click of title?

我已经使用Echart JS创建了条形图,如何自定义标题栏的单击。 我试过使用triggerEvent,但单击标题时不起作用,仅对统计信息起作用。

的jsfiddle

var myChart = echarts.init(document.getElementById('main'));

function openTab(){
// Custom code will go here
    return 'https://www.google.com'
}

option = {
  title: {
    x: 'left',
    text: '12 total',
    link : function(){
        openTab();
    }
  },
  grid: {
    left: 50,
    top: 50,
    right: 50,
    bottom: 0
  },
  xAxis: [{
    type: 'category',
    show: false,
    data: ['Test 1', 'Test 2']
  }],
  yAxis: [{
    type: 'value',
    show: false,
    min: 0
  }],
  series: [{
    type: 'bar',
    itemStyle: {
      normal: {
        color: '#3b4563',
        label: {
          show: true,
          position: 'top',
          formatter: '{c} {b}'
        }
      }
    },
    data: ['2', '10']
  }]
};



myChart.setOption(option);

我用过https://ecomfe.github.io/echarts-examples/public/index.html#chart-type-bar

最新版本的echart js可以做到这一点。

版本:4.2.0-rc.2

标题现在具有triggerEvent选项:

title : {
            text: 'Test titlr',
            triggerEvent: true
        },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM