2017-12-27 27 views
0

私は質問解決することができた:Uncaught TypeError: Cannot read property 'showBarChart' of undefined in ReactNVD3ツールチップのバグ

var that = this; 
chart.tooltip.contentGenerator(function (d) { 
     var html = "<div>"; 
     d.series.forEach(function(elem){ 
     Object.keys(data_obj).forEach(function(key_1) { 
      var outer_obj = data_obj[key_1]; 
      if (outer_obj["key"] === elem.key) { 
       that.showBarChart(elem.key); 
       var expr = outer_obj["values"][0]["expr"]; 
       html += "<p>" + elem.key + "</p>"; 
       html += "<p>x = " + d.value + ", y = " + elem.value + "</p>"; 
      } 
     }); 
     }) 
     html += "</div>"; 
     return html; 
    }); 

しかし、解決策はnvd3tooltipmouse outに消えないscatterChartに非常に奇妙なバグにつながったのと同じページ上にとどまります。私はそれを修正する可能性がどのように

enter image description here

答えて

0

問題は、componentDidUpdateで、私はcreateScatterChartと呼んでいました。私はそれをコメントし、それは正常に動作するようになった。 - なぜあなたが反応してNVD3を使用しているのではなくD3の特定の実装に反応Trace why a React component is re-rendering

componentDidMount() { 
this.createScatterChart() 
} 

componentDidUpdate() { 
//this.createScatterChart() 
} 

Calling this.setState() within the component. This will trigger the following component lifecycle methods shouldComponentUpdate > componentWillUpdate > render > componentDidUpdate

+0

私がお奨め尋ねました:私は疑問に記述されることがわかっているどうやらためReactワークフローの起こっていました? – jeznag

+0

React-D3のライブラリをいくつか送ってもらえますか?私はNVD3を使用すれば私が書くコードが少なくて済むと思うので、私は仕事を減らそうとしています。正直なところ、私は完全にはわかりませんが、それは私が今考えていることです。 –

+1

https://emeeks.github.io/semiotic/#/semiotic/examples http://nivo.rocks/#/ https://uber.github.io/react-vis/ ます。http: //formidable.com/open-source/victory/gallery/ – jeznag