未处理的Promise拒绝:this.getData不是函数

时间:2017-04-05 07:45:15

标签: angular plotly

我正在使用Angular 2进行绘图。我尝试从函数(eventdata){}函数调用getData()函数。但我犯了错误。

我提到this code

我的代码是:

<script>
var trace1 = {
 x: ['2013-10-04 22:23:00', '2016-10-06 22:23:00',  '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
 y: [1, 3, 6,9, 4, 5],
 fill: 'tozeroy',
 fillcolor: 'red',
 text: server1,
 hoverinfo: "x+y+text",
 name:"Server 1",
 type: 'scatter',
 mode:"markers",
 marker:
 {
  size:5,
  color:"gray"
 },
uid:"c2e171"
};
var layout = {
 margin: {
  l: 20,
  r: 40,
  b: 40,
  t: 10
 },
legend: {
"orientation": "h"
},
 yaxis : {fixedrange: true},
};
var data = [trace1];
Plotly.newPlot('myDiv', data,layout);

var plotDiv = document.getElementById('myDiv');
plotDiv.on('plotly_relayout',
function(eventdata){  
  this.minDate = new Date(eventdata['xaxis.range[0]']);
  this.maxDate = new Date(eventdata['xaxis.range[1]']);
  this.getData();
}); 

getData() {
  console.log("getData() function");
}

1 个答案:

答案 0 :(得分:1)

像这样使用你的代码

var plotDiv = document.getElementById('myDiv');
plotDiv.on('plotly_relayout',
(eventdata) =>{  
    this.minDate = new Date(eventdata['xaxis.range[0]']);
    this.maxDate = new Date(eventdata['xaxis.range[1]']);
    this.getData();
}); 

getData() {
  console.log("getData() function");
}