Chart.js: Will it ever be possible for the update function to update the options of the chart as well?

Created on 26 Feb 2016  ·  5Comments  ·  Source: chartjs/Chart.js

Hi,

i'm looking to switch between a regular bar chart and a stacked bar chart on the fly. At the moment this is only possible by destroying and re-creating the chart but this causes a flicker when doing so (as the chart is essentially being removed and put back onto the web page). I thought it would be much more efficient to be able to update the options seeing as we are only looking to toggle stacked and the title of the chart. Just wondering if this will ever be possible?

Thanks

help wanted enhancement

Most helpful comment

Hi, thanks for the reply.

I understand that it would cause a performance decrease. Was just thinking you could have a prototype method (hardUpdate for example) that people can choose to call as an alternative to the update function, which would as a result update the entire chart, including options. Kind of like how when update is called, render is subsequently called, but instead it'd be hardUpdate, calling update which in turn calls render (so hardUpdate would only contain the required code to update the options). Just so the functionality is there if someone were to require it without forcing the performance decrease on everyone who wanted to call update.

Thanks again :)

All 5 comments

@dibsyjr1 this is not currently supported in either version 1 or version 2. It should be possible, the most annoying thing would be the performance decrease caused by re-merging the config with the global config.

Hi, thanks for the reply.

I understand that it would cause a performance decrease. Was just thinking you could have a prototype method (hardUpdate for example) that people can choose to call as an alternative to the update function, which would as a result update the entire chart, including options. Kind of like how when update is called, render is subsequently called, but instead it'd be hardUpdate, calling update which in turn calls render (so hardUpdate would only contain the required code to update the options). Just so the functionality is there if someone were to require it without forcing the performance decrease on everyone who wanted to call update.

Thanks again :)

Yup, I think we can provide this functionality though it won't make the 2.0.0 release

Okay that's cool, thanks very much

Why not just add another function for this? And don't use update() as God-function, but divide it by steps, or even remove it leaving something like updateConfig(), updateData() and render().

Was this page helpful?
0 / 5 - 0 ratings