dojchek

Update chart data - setChartData() vs FusionCharts constructor

Recommended Posts

Hello,

I need to update the chart data - (from the JSON). However I am slightly confused on how to do it properly.

The first solution is to render the chart on init and use setJSONData() method for data updates. The thing which confuses me is the remark from fusioncharts documentation :

Quote

A preferrable alternative to using this method is to pass chart data to the dataSource attribute of the FusionCharts constructor.

 

So, my second solution was to re-render the chart every time new data appears, by disposing the "chart" and then creating a new chart object (with datasource set to new data) and finally render it with render() function.

Both approaches seems to work, where the 2nd one is a bit faster in most cases (depends on chart type/data size).

My question is - What are the pros/cons for each approach and which one is actually preferable? All the fiddle examples and documentation point me to use setChartData/setJSONData, but there is that one remark which makes me think it should be done via FusionCharts constructor and dataSource attribute.

Thanks

 

 

 

 

Edited by dojchek

Share this post


Link to post
Share on other sites

Hi,

Apologies for the delay.

Regarding your first query i.e passing data to the dataSource attribute of the FusionCharts constructor when setJSONData api method is used please check this fiddle for reference http://jsfiddle.net/ggg1jkns/

For the second problem, please set asyncRender to 0 at the constructor level in order to check the performance using setJSONData api method and disposing and re rendering the chart, as asyncRender when set to 1 all the chart configurations are executed in a separate thread before rendering the graphics of the chart (that is carried out when the render() function is called). And when asyncRender is set to 0 all the chart configurations are executed in the same thread. 

Please note from version 3.12.0 by default asyncRender is set to 1 when a chart is rendered.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now