Sign in to follow this  
Rahul Kumar

Dynamically update swf type and data via setDataXML

Recommended Posts

If I'm doing something like this to update XML or URL how can I also update the chart swf type

 

 

 


function updateChart(xml){

  var c=getChartFromId('chartId1');//pass your chart's id here in case the id differs

  c.setDataXML(xml);

}

 

 

 

I want to also dynamically update the swf from pie to bar etc.

 

 

 

Is this possible?

 

 

 

I saw an example in the forum that did something like this

 


  chart1.setAttribute('swf', 'pathtocharts/charts/' + chartType + '.swf');

  chart1.render('chartId1');

 

 

 

Thank you for your help!

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

Could you please follow the attached file?

The example attached uses 3 text input box where you can provide

a) the chart type i.e. only the chart name (e.g. pie3d/pie2d/doughnut2d etc.)

:) chart width

c) chart height

 

Please note that this is a very basic sample and needs to be modified extensively before actual implementaiton with error trapping etc. Moreover, i am using a sample single series XML.

Also note that the JavaScript chart object is kept global so that it can be accessed by all functions.

ChangeChart.zip

Share this post


Link to post
Share on other sites

Thanks for sending me over that example. I have tried the following. chart_myFirst is global and when I run this sending it a swf it does not work. I do not get an js error or warning. Just cleared out the report that was there. If I send without the swf and just url the report updates properly.

 

 

 


function updateReport(url,swf)

{	



 if(swf!=null){

 		chart_myFirst.setAttribute("swf",swf);

 		chart_myFirst.setDataURL(url);

 		chart_myFirst.render('myFirstDiv');   		

 }else{

 		chart_myFirst.setDataURL(url);

 }

}

 

 

 

Any ideas?

Share this post


Link to post
Share on other sites

this is initial chart initialization when viewing html source. The div containing the obj is myFirstDiv

 

	

//Instantiate the Chart	

	var chart_myFirst = new FusionCharts("../classes/fusioncharts/MSLine.swf", "myFirst", "340", "180", "0", "1");

	//Set the dataURL of the chart

	chart_myFirst.setDataURL("index.php%3Ffuse%3Dreports%26indashboard%3D1%26noheaderfooter%3D1%26view%3DViewReport%26report%3DIncome_Growth%26type%3DIncome%26graphdata%3D1")

	//Finally, render the chart.

	chart_myFirst.render("myFirstDiv");	

Edited by Guest

Share this post


Link to post
Share on other sites

Ok it seems the path was an issue... now here are the results.

 

 

 

 

 


 		chart_myFirst.setAttribute("swf",swf);

 		chart_myFirst.setDataURL(url);

 		chart_myFirst.render('myFirstDiv');   

 

 

 

It looks like url is not being sent as I loop through 4 reports and they are all using the same data. So when the report has a swf that matches the data from the initial report the report displays. For example MSLine and MSColumn2d show up since the same data works on both. Again the setDataURL is not working since it displays the same data though it is using the correct swf. When I switch it to say a pie then I get a "No Data To Display".

 

 

 

If I comment out the set attribute and render so..

 

 

 


    chart_myFirst.setDataURL(url);

 

 

 

When this is used then the data is updated but the graph of course is not.

 

 

 

Lastly if I change the setDataURL after the render.. like

 


 		chart_myFirst.setAttribute("swf",swf);

 		chart_myFirst.render('myFirstDiv');   

               chart_myFirst.setDataURL(url);

 

 

 

I get a function setDataURL does not exist.

 

 

 

I've been at this for a while as I work on other items, but I hope this is a common issue others are having when dynamically changing graphs in the same graph object.

Share this post


Link to post
Share on other sites

Hi Alberto,

 

 

 

Could you please make sure that XML for MSLine and MSColumn2D chart is different than Pie chart? Since Pie chart is a single series chart and MSLine, MSColumn2D are Multi-Series chart.

Edited by Guest

Share this post


Link to post
Share on other sites

Hi,

Generally if you change chart and render the chart again you would need to setDataURL/setDataXML before the render() function is called.

If you set it later you would need to wait for the char to load and track the loading using FC_Rendered() function and then use :

function FC_Rendered(DOMId){

var x=getChartFromId(DOMId);

x.setDataULR(youURL);

}

Note to set registerWithJS option on i.e. 1 to get chart from ID and setDataURL after that.

It would be better if you follow the FusionCharts.js 's conventional rendering model while chaging chart too.

var c=new FusionCharts(swf,....);

c.setDataXML(...);  // or c.setDataURL(..)

c.render(divId);

 

This would replace an existing chart in the div (with divId) and render a new chart (of new type)

Share this post


Link to post
Share on other sites
Sudipto Choudhury (11/1/2008)
Hi,

 

 

 

It would be better if you follow the FusionCharts.js 's conventional rendering model while chaging chart too.

 

 

 

var c=new FusionCharts(swf,....);

 

c.setDataXML(...); // or c.setDataURL(..)

 

c.render(divId);

 

 

 

This would replace an existing chart in the div (with divId) and render a new chart (of new type)

 

 

 

Can I not just use the same js object already created as demonstrated above

 

 

 


 		chart_myFirst.setAttribute("swf",swf);

 		chart_myFirst.render('myFirstDiv');   

               chart_myFirst.setDataURL(url);



 

 

 

I will try with a brand new object

Share this post


Link to post
Share on other sites

I went ahead and used your suggestion and that seemed to work just fine.

 

 

 


var c = new FusionCharts(swf, "myFirst", chart_myFirst.getAttribute('width'), chart_myFirst.getAttribute('height'), "0", "1");

 

 

 

I used the getAttribute on the existing chart to insure that the sizes were the same.

 

 

 

Also, for anyone reading this thread. Do not forget to encode ( escape) your url in setDataUrl

 

 

 

Thanks again

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