Update the this.state.datasets and call this.forceUpdate
1 works well only update datasets without changing a number of datasets.
2 works well all manipulation.
Implementation
The source code below is effective when 1.
But it is not effective when 2. Because the chart.data.datasets is already updated.
assign all from the next datasets to the current chart
```
// assign all of the properites from the next datasets to the current chart
nextProps.data.datasets.forEach(function(set, setIndex) {
var chartDataset = chart.data.datasets[setIndex];
for (var property in set) {
if (set.hasOwnProperty(property)) {
chartDataset[property] = set[property];
}
}
});
```
Background
There is two way to update datasets of a chart.
this.setState
this.state.datasets
and callthis.forceUpdate
1 works well only update datasets without changing a number of datasets. 2 works well all manipulation.
Implementation
The source code below is effective when 1. But it is not effective when 2. Because the
chart.data.datasets
is already updated.assign all from the next datasets to the current chart
``` // assign all of the properites from the next datasets to the current chart nextProps.data.datasets.forEach(function(set, setIndex) { var chartDataset = chart.data.datasets[setIndex]; for (var property in set) { if (set.hasOwnProperty(property)) { chartDataset[property] = set[property]; } } }); ```https://github.com/jhudson8/react-chartjs/blob/chartjs-v2/lib/core.js#L57
Question
Which method is better to change the datasets of a chart?