[BUG?] How to update a chart by replacing entire data object

Expected Behavior

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.

Current Behavior

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.

  1. Open https://jsfiddle.net/mdt86/219hry2s/7/
  2. Click on the button REPLACE ENTIRE DATA OBJECT
  3. Verify that the chart is not updated with the new values (cfr. newDataObject), but only value[0] in the first dataset is updated (see code for reference)
  4. Check lines 132-140 reported here
			// 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[0].data[0] = 1000;


Although modifying 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

Author: Fantashit

2 thoughts on “[BUG?] How to update a chart by replacing entire data object

Comments are closed.