2017-05-30 55 views
0
render(){ 
     let conf={ 
      chart: { 
       type: 'spline', 
       animation: Highcharts.svg, // don't animate in old IE 
       marginRight: 10, 
       events: { 
        load:function(){ 
         var series = this.series[0]; 
         setInterval(() =>{ 
          var x = new Date().getTime() // current time 
          y = this.props.y 
          series.addPoint([x,y], true, true); 
         }, 900); 
        } 
       } 
      }, 
      title: { 
       text: 'Live random data' 
      }}} 

的負載,我無法訪問this.props.y負載的功能內,甚至沒有任何構造函數的變量。 我曾嘗試使用箭頭函數而不是函數然後圖形顯示什麼都沒有。提前不能訪問this.props在highcharts

回答

0

在箭頭功能 感謝您的幫助,勢必圖表對象,不是組件。

您可以將這個緩存在渲染中的變量中,然後在超時時使用它。

render(){ 
    const component = this 

    let conf={ 
     chart: { 
      type: 'spline', 
      animation: Highcharts.svg, // don't animate in old IE 
      marginRight: 10, 
      events: { 
       load:function(){ 
        var series = this.series[0]; 
        setInterval(() =>{ 
         var x = new Date().getTime() // current time 
         y = component.props.y 
         series.addPoint([x,y], true, true); 
        }, 900); 
       } 
      } 
     }, 
     title: { 
      text: 'Live random data' 
     }}}