luftikus143

"getChartFromID is not defined"

Recommended Posts

Hi there,

 

 

 

I am using the example "Combining FusionCharts, PHP & Javascript (dataURL) method".

 

 

 

But for the

 

var chartObj = getChartFromId("name_of_chart");

 

I get the error:

 

getChartFromID is not defined

 

 

 

My code is:

 

< div id="chartdiv" align="center">



.... javascript opening here.... 

 var chart = new FusionCharts("http://localhost/etc/FusionCharts_Evaluation/Charts/Bubble.swf", "ChartId", "1000", "700", "0", "0");

 chart.setDataURL("<?php echo $strDataURL; ?>");

 chart.render("chartdiv");





function updateChart(year)

{

	var strURL = "graph_scatter-data.php?selectedID=1510&selectedYear=" + year + "&xaxis=";

	strURL = unescape(strURL);

	var chartObj = getChartFromID("ChartId");

	alert(chartObj);					

	chartObj.setDataURL(strURL);



}

.... javascript close here.... 



< a href="#" onclick="updateChart('1995');">older year< /a>

 

 

 

I tried it both with "ChartID" and "chartdiv", but neither worked. (I guess ChartID should be the right one.)

 

 

 

Can you help me?

Share this post


Link to post
Share on other sites

It seems that in the new FusionCharts() line, the last paramwter is set to '0'. That should be a '1'. It registers the chart with Javascript.

 

 

 

Try that.

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Can you make sure that FusionCharts.js is properly included in the page? Ideally, the error message should have been different for improper usage. But, if it's giving "getChartFromID is not defined", that means the function has not been registered.

Share this post


Link to post
Share on other sites

Can you try putting this code block in the

section of your document:

 

 

 

function updateChart(year)

 

{

 

var strURL = "graph_scatter-data.php?selectedID=1510&selectedYear=" + year + "&xaxis=";

 

strURL = unescape(strURL);

 

var chartObj = getChartFromID("ChartId");

 

chartObj.setDataURL(strURL);

 

 

 

}

Share this post


Link to post
Share on other sites

Hi,

I hope the browser error prompt was right . There is no method called getChartFromID . The function's name is getChartFromId(). The D makes the difference.

moreover use escape() function instead of unescape() to encode the URL.

function updateChart(year) { 
	  var strURL = "graph_scatter-data.php?selectedID=1510&selectedYear=" + year + "&xaxis="; 
	  strURL = escape(strURL); 
	  var chartObj = getChartFromId("ChartId"); 
	  chartObj.setDataURL(strURL); 
} 

Share this post


Link to post
Share on other sites

I've implemented an automatic call of the update function, so that it displays every second or so the selected variables with another year.

 

 

 

Is there a way to avoid that the whole chart is being reloaded? It looks a bit ugly and is surely pretty tiresome.

 

 

 

Here is again the URL. And then click on "automatic change" above the listing of the years.

 

 

 

Thanks for any advice!

Share this post


Link to post
Share on other sites

Hi,

YOu can try using AJAX (getting data from URL) to retrieve the XML in a javascript variable. Then use setDataXML() method to reload the chart data from that variable. Remember to set animation='0' i.e. off if you are feeling that the you need less delay.

This process may take the same delay but it wont erase the chart and go for a long retrieving data prompt. Because data will be retrieved by AJAX and not chart. In that time the old chart willl remain in display. When you get the data in js variable you set it to the chart  and the char refreshes the data in a swish......

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