alpsilva

Chart loads only initialized data

Recommended Posts

i'm trying to process data from a query. So I create a JSON object and populate it using a loop, like so:

 

var processedData = [{
	label: "teste",
	value: 123
}, {
	label: "teste2",
	value: 321
}];

if (dataParse.response) {
	dataParse = dataParse.response;
	for (var aux of dataParse) {
		jsonAux = {
			label: aux.departamento,
			value: parseInt(aux.quantidade)
		}
		processedData.push(jsonAux);
	}
}


after the loop, the object is returned and used as chart data. As seen in the image attached, it is done without problems (For testing purposes, i initialized the object "processedData" with two test elements: "teste1" and "teste2"). But FusionChart can only load the initiliazed elements.

I don't have any idea why this is happening and already tried many different ways to do this.

Would be really glad if someone could be of use. Thanks in advance.

help.png

Share this post


Link to post
Share on other sites

Hi,

 

It seems that the chart is rendering using the initial values set to the "processedData" variable, but the "processedData" variable is getting updated with the fetched values after the chart is rendered(with initial data). As it is taking a while to execute the query to fetch the data, by then it is rendering the chart with the initial data.

Please ensure that you are rendering the chart after the data is fetched and the "processedData" variable is updated. You could check that by setting a delay accordingly to render the chart so that the variable is updated with the fetched data.

Check these samples for reference :
Fiddle similar to your scenario : http://jsfiddle.net/va8nyfzx/3/
Fiddle setting a delay to render the chart : http://jsfiddle.net/va8nyfzx/4/

 

Thanks,

Akash.

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