tobyjoiner

2 dynamic charts in one page

Recommended Posts

I have been trying to get 2 charts that are basically the same to work in the same page. I can take either one out and the other works fine, but when I have both and I try to run the function on either one of them, it only updates the first one on the page. I am sure I am just missing something easy, but can't find it.

 

 

 

These are the 2 functions I use to call get the new chart data. chartdata.php returns xml code, and that looks fine, and like I said above, works fine with either one of the charts. This is in the head section of the page.

 

function changeChart1Date(modDate, modLength) {

   chart1.setDataURL("chartdata.php?date="+modDate+"&length="+modLength);

}

 

function changeChart2Date(modDate, modLength) {

   chart2.setDataURL("chartdata.php?date="+modDate+"&length="+modLength);

}

 

This is in the body and obviously loads the charts to begin with. If I change the data on one of them from here they both work fine, and show separate data. Its just the reload that is broken. The code below is in the body section and has the 2 divs nearby.

 


var chart1 = new FusionCharts("/chart/MSLine.swf", "sampleChart", "650", "300", "0", "1");

chart1.setDataURL("chartdata.php");

chart1.render("chart1div");

var chart2 = new FusionCharts("/chart/MSLine.swf", "sampleChart", "650", "300", "0", "1");

chart2.setDataURL("chartdata.php");

chart2.render("chart2div");

 

Thanks for any help,

 

 

 

Toby

Share this post


Link to post
Share on other sites
Guest Madhumita

Hello,

Welcome to FusionCharts Forum. :)

The issue arose as both the charts had the same id : sampleChart

Please consider changing the codes to the following:

function changeChart1Date(modDate, modLength) {

  var chart1 = getChartFromId("sampleChart1");

  chart1.setDataURL("chartdata.php?date="+modDate+"&length="+modLength);

}

 

function changeChart2Date(modDate, modLength) {

  var chart2 = getChartFromId("sampleChart2");

  chart2.setDataURL("chartdata.php?date="+modDate+"&length="+modLength);

}

var chart1 = new FusionCharts("/chart/MSLine.swf", "sampleChart1", "650", "300", "0", "1");

 

chart1.setDataURL("chartdata.php");

 

chart1.render("chart1div");

 

var chart2 = new FusionCharts("/chart/MSLine.swf", "sampleChart2", "650", "300", "0", "1");

 

chart2.setDataURL("chartdata.php");

 

chart2.render("chart2div");

Hope this helps.

Awaiting your reply. :(

Share this post


Link to post
Share on other sites
Guest Madhumita

Hello,

You are most welcome.

We thank you too for appreciating our zeal to help FusionCharters.

Happy FusionCharting. :)

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