user15455820
user15455820

Reputation:

chart.js update() function not working correctly

Ive ran into a problem with chart.js where the animation isnt playing correctly even though the update() function isnt set to 0, the animation only plays "once" and after it finishes it doesnt update anymore. Any help would be greatly appreciated.

my update function is below.

function B2D1(){
    chart2.config.data = data4;
    chart2.options.title.text = 'Cyberpunk 2077 - 1080p, Highest Preset';
    chart2.update();
}

Upvotes: 1

Views: 286

Answers (1)

LeeLenalee
LeeLenalee

Reputation: 31431

If you want to update your data while it being animated you cant replace the data object. In order to change the data you will have to change the data array directly. If you do that the animations keep playing

So instead of doing chart2.config.data = data4; you will need to do myBar.data.datasets[datasetIndex].data = newData;

Upvotes: 2

Related Questions