2017-05-05 205 views
0

我正在使用Pie Highchart,我想在点击事件中调用一个函数。我不想写如下的函数逻辑。这里可以调用一个外部函数吗?如何在Highcharts中添加点击事件功能

 plotOptions: { 
          pie: { 
           allowPointSelect: true, 
           cursor: 'pointer', 
           dataLabels: { 
            enabled: false 
           }, 
           showInLegend: true, 
           point:{ 
            events:{ 
             click: function(oEvent){ 
             alert(oEvent.point.name); 

             } 
            } 
           } 
          } 
         }, 

这个回调函数将有很多行代码,所以我想在其他地方定义它,并调用它的plotoptions。让我知道,该如何实现呢

+0

是啊,简单地定义一个函数:'功能myFun(){}'然后再使用它:'点击: myFun'。 –

回答

0

它做下列方式

Fiddle

plotOptions: { 
    pie: { 
     allowPointSelect: true, 
     cursor: 'pointer', 
     dataLabels: { 
     enabled: true, 
     format: '<b>{point.name}</b>: {point.percentage:.1f} %', 
     style: { 
      color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' 
     } 
     }, 
     point: { 
     events: { 
      click: function(oEvent) { 
      callExternalFunction(oEvent.point.name); //call function with arguments 
      } 
     } 
     } 
    } 
    }, 
function callExternalFunction(obj){ 
    console.log(obj); 
} 
相关问题