reactjs / react-chartjs

common react charting components using chart.js
MIT License
2.93k stars 301 forks source link

TypeError when setting new data that has less labels than original number of labels #33

Open adamscybot opened 9 years ago

adamscybot commented 9 years ago

If you update data and the new data has less labels than the previous number of labels you get the error:

TypeError: Cannot set property 'value' of undefined

Its related to the line

chart.datasets[setIndex][dataKey][pointIndex].value = val;

Should probably trigger a redraw...

joshhornby commented 9 years ago

I have had this issue as well, I added redraw as per the docs

if data passed into the component changes, points will animate between values using chart.js' .update(). If you want the chart destroyed and redrawn on every change, pass in redraw as a prop. For example <LineChart data={this.state.chartData} redraw />

If you want to make this dynamic please submit a PR.

mnishiguchi commented 9 years ago

I made a component for Chart.js from scratch. I destroy an old instance and re-initialize a chart on componentWillUnmount rather than componentWillReceiveProps. Also, I replace the whole data every time the component is provided with new data. This way, we can keep our code simple. I share with you a simple helper method I wrote to generate a chart component class.

Please check out InteractiveChartComponent.