According to #1646,
You can now change the entire data object of the chart and then call update and the chart will work. The line sample has been update to test this behaviour.
Note to whomever reviews this: please test all chart types before merging.
Replacing the entire
data object in a chart and calling
update() on the chart, does not update the chart correctly.
Steps to Reproduce
Following the example https://github.com/chartjs/Chart.js/blob/master/samples/line/line.html I created a test.
- Open https://jsfiddle.net/mdt86/219hry2s/7/
- Click on the button REPLACE ENTIRE DATA OBJECT
- Verify that the chart is not updated with the new values (cfr.
newDataObject), but only
valuein the first dataset is updated (see code for reference)
- Check lines 132-140 reported here
console.log(myLine.data); // comment out: this one would work, but I want to try a different approach (see following lines) // config.data = newDataObject; // the newDataObject does not override myLine.data object: why??? myLine.data = newDataObject; // ... but updating a single value works: why??? myLine.data.datasets.data = 1000; console.log(myLine.data); window.myLine.update();
config.data (cfr. code above) would solve this issue, I would like to understand why calling
myLine.data = newDataObject does not work.
My project is indeed quite complex: I create the chart in one place, then I would like to update my chart later on in another place, by calling
myLine.data = newDataObject.
Ideas are welcome!
- Chart.js version: 2.x (2.4.0 in the test linked above)
- Browser: Chrome