Sign in to follow this  
Rahul Kumar

Updating data isn't working

Recommended Posts

I'm getting particular requests for particular charts from a drop-down (comes in as var "drop"). I have a json object myPageData, keyed on those drops that says which type of chart we want for each possible chart we're building.

 

 

 

The idea here is, if we've already got that chart type up, don't bother to reload, just feed it fresh data. So if we're changing chart types, fetch up a new .swf, otherwise just get the chart from Id and bounce its data.

 

 

 

		

var chartType = "FCF_" + myPageData[drop] + '.swf';

var myChart;

var currentChart;

if (chartType != currentChart) {

myChart = new FusionCharts("fusioncharts/" + chartType, "myChartId", "800", "400");

} else {

myChart = getChartFromId("myChartId");

}

currentChart = chartType;

myChart.setDataURL("esmt/feedxml.pl?" + drop);

myChart.render("chartdiv");

 

 

 

The load-the-new-chart-type part works great, but when I try to refresh the current chart, I get "myChart.setDataUrl() is not a function". What's up with that?

Share this post


Link to post
Share on other sites

Oops... If I'd looked down ONE THREAD I'd have found my answer: this isn't supported in FCFree. Time to pull out the credit card, I guess.

Share this post


Link to post
Share on other sites

Okay, so now I'm working with the demo of FusionCharts v3, and it's still not working. Fundamentally the same code as above. I set up an alert() to tell me that it's in the reusing-the-chart branch, and when it is, the call to myChart.setDataURL fails with "is not a function".

 

 

 

Thoughts?

Share this post


Link to post
Share on other sites

Hi,

 

 

 

The issue you are facing just because you have not invoked Flash ExternalInterface, which is done by passing registerWithJS="1" to the chart's swf. You would need to render the chart first time using this parameter.

 

 

 

Please see the code below, I have added two more parameter ("0", "1") into the FusionCharts constructor, the first one (,"0","1") will render the in debug mode(if value is 1), and the second one (,"0","1") will expose Flash API function, so that we can call it (setDataXML/setDataURL/Print/saveAsImage) from JavaScript.

 

 

 

var chartType = "FCF_" + myPageData[drop] + '.swf';

 

 

 

var myChart;

 

 

 

var currentChart;

 

 

 

if (chartType != currentChart) {

 

 

 

myChart = new FusionCharts("fusioncharts/" + chartType, "myChartId", "800", "400","0","1");

 

 

 

} else {

 

 

 

myChart = getChartFromId("myChartId");

 

 

 

}

 

 

 

currentChart = chartType;

 

 

 

myChart.setDataURL("esmt/feedxml.pl?" + drop);

 

 

 

myChart.render("chartdiv");

Share this post


Link to post
Share on other sites

Okay, good....

 

 

 

The next gotcha I discovered is, you only call myChart.render() on initial load. After that, just calling setDataURL() re-renders the graph. The chart object you get with getChartById() doesn't have that method either.

 

 

 

Thanks!

Share this post


Link to post
Share on other sites

Hi,

 
I think the code is now working fine, as you said chart is getting rendered for the first time then it cought error at second run because myChart.render is not exposed to JavaScript, now to resolve that issue you would need to change your code logic.

Share this post


Link to post
Share on other sites

Yeah, it's all good, I just thought I'd note the next thing I stumbled over, for anyone who reads this thread in the future. render() is only needed on first load, and after, that setting the data URL causes the redraw.

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Please see, the things are like this:

 

 

 

.render("...") method is NOT a flash chart's ExternalInterface method, instead it is a derived method of FusionCharts class. SO IT WON'T GET INVOKE SECOND TIME if you get the chart reference by using getChartFromId. You can only use it whenever you re-create the chart using new FusioCharts("........","..","..".......);

 

 

 

Now if you get the chart reference by using getChartFromId, & use setDataURL or setDataXML then it does re-render the chart but not re-loads it. consider this as like "If you want to play a movie, you start your player then you load movie, start playing it, after completion of movie, you want to show another, then what you do? You just open a new file & starts playing another, that is exactly what FusionCharts do, it open it self first time, but if provided new data then FusionCharts re-loads the new data from beginning"

 

 

 

And if you want to load new data using dataURL/dataXML & want it to be look static then you could use animation='0' in [chart...animation='0'...] element in the new XML.

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
Sign in to follow this