2017-03-05 39 views
-1

我正在使用Highstock 5.0.7。我的圖表選項存儲在數據庫中,我正在讀取它以獲取繪製的圖表。我需要在點擊堆積的柱形圖時調用一些ajax函數。堆積柱狀圖顯示正確,但問題是,當我點擊堆棧時,我得到一個JS錯誤,說e.call不是一個函數。下面是JS錯誤。Highcharts - 事件點擊時的javascript函數給出錯誤e.call不是函數

highstock.js:29 Uncaught TypeError: e.call is not a function 
a.fireEvent @ highstock.js:29 
E.firePointEvent @ highstock.js:271 
a.Pointer.onContainerClick @ highstock.js:209 
    l.onclick @  highstock.js:210 

在JavaScript是下plotOption->系列 - >點 - >事件 - 寫在圖表選項>點擊

"chart": { 
    "type": "column" 
}, 
"credits" : { 
    "enabled" : false 
}, 
"title" : { 
    "text" : "chartName" 
},   
"xAxis": { 
    "categories": [] 
}, 
"yAxis": { 
    "min": 0, 
    "stackLabels": { 
     "enabled": true, 
     "style": { 
      "fontWeight": "bold", 
      "color": "gray" 

     } 
    } 
}, 
"legend": { 
    "enabled":true 
}, 
"tooltip": { 
    "headerFormat": "<b>{point.x}</b><br/>", 
    "pointFormat": "{series.name}: {point.y}<br/>Total: {point.stackTotal}" 
}, 
"plotOptions": { 
    "column": { 
     "stacking": "normal", 
     "dataLabels": { 
      "enabled": true, 
      "color": "white", 
      "style": { 
       "textShadow": "0 0 3px black" 
      } 
     } 
    }, 
    "series": { 
     "cursor": "pointer", 
     "point": { 
      "events": { 
       "click": "function() {alert(y.value);}" 
      } 
     } 
    } 
}, 
"series": [] 
}  

下面是腳本標記,我現在用

<script src="./resources/js/highstock/highstock.js"></script> 
     <script src="./resources/js/highstock/highcharts-more.js"></script> 
     <script src="./resources/js/highstock/highcharts-3d.js"></script> 
     <script src="./resources/js/highstock/modules/solid-gauge.js"></script> 
     <script src="./resources/js/highstock/modules/exporting.js"></script> 
     <script src="./resources/js/highstock/modules/offline-exporting.js"></script> 
     <script src="./resources/js/highstock/modules/drilldown.js"></script> 
+1

你需要[EVAL(https://www.w3schools.com/jsref/jsref_eval.asp)點擊事件功能 - 如果你不這樣做,你有一個字符串,而不是在click事件上調用的函數。 – morganfree

回答

0
series: { 
     cursor: 'pointer', 
     point: { 
      events: { 
       click: function() { 
       console.log("this : ",this) 
       console.log('this.y',this.y) 
        alert(this.y); 
       } 
      } 
     } 
    } 
+0

你可以通過console.log.as調試深3015 jiddle工作正常 – Gourav

0

您的點擊事件定義爲

series: { 
     cursor: 'pointer', 
     point: { 
      events: { 
       click: function() { 
        alert(this.y); /*not y.value*/ 
       } 
      } 
     } 
    } 

fiddle演示

Highcharts Reference

+0

我將它修改爲「this.y」,但我仍然得到一個類似的錯誤,名爲highstock.js:29 Uncaught TypeError:e.call不是函數 – ZEE

+0

@ZEE可以添加小提琴嗎?我的小提琴工作 –