Sign in to follow this  
pyrite

Setchartattribute Doesn't Stay After Setjsonurl

Recommended Posts

Hello,

 

I'm trying to update a chart with new JSON data, and also change the chart's subcaption to reflect the new data. This code works, sort of, it changes the subcaption, then refreshes the chart with the new data and puts it back to the old subcaption. What am I doing wrong? :(

 

<html>
<head>
<title>On-Time Delivery by Work Area</title>
<script type="text/javascript" src="/configurator/js/fc/Charts/FusionCharts.js"></script>
</head>
<body>
   	<div style="float: right">
   	<select id="selmonth" onchange="chgmonth();">
   	<?php
   	$s = '';
   	for ($i = 1; $i <= 12; $i++) {
           	if ($i <= date("n")) {
                   	if ($i == date("n")) {
                           	$s = ' selected="selected"';
                   	}
                   	echo '<option value="'.$i.'"'.$s.'>'.date("F Y", mktime(0, 0, 0, $i+1, 0, date("Y"), 0)).'</option>';
           	}
   	}
   	?>
   	</select>
   	</div>
   	<p> </p>

   	<div id="chartContainer">FusionCharts will load here!</div>
   	<script type="text/javascript">
   	<!--
   	var myChart = new FusionCharts( "/configurator/js/fc/Charts/MSColumnLine3D.swf", "otdbyworkareaytdchart", "95%", "95%", "0", "1" );
   	myChart.setJSONUrl("/configurator/metrics/getotdbyworkareaytd");
   	myChart.render("chartContainer");

   	function chgmonth() {
           	chartReference = FusionCharts("otdbyworkareaytdchart");
           	var action = document.getElementById('selmonth');
           	chartReference.setChartAttribute( "subcaption" , action.options[action.selectedIndex].text );
           	chartReference.setJSONUrl("/configurator/metrics/getotdbyworkareaytd/"+action.value);
   	}
// -->
   	</script>
</body>
</html>

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Welcome to FusionCharts Forum!smile.gif

 

It seems that you are providing the old subcaption when the chart refreshes with the new data.

 

Please try the same by providing the subcaption you are looking for while updating the chart.

 

Hope this helps.

Share this post


Link to post
Share on other sites

I don't understand what you just said, but:

 

myChart.setJSONUrl("/configurator/metrics/getotdbyworkareaytd");

 

This returns the chart data in JSON format, with a subcaption set.

 

The code above changes the JSON data, but I am trying to override the subcaption after I call setJSONUrl(). And it works for a second, but then goes back to the subcaption defined in the JSON data instead of the one set by setChartAttribute.

 

Share this post


Link to post
Share on other sites

I solved the problem by just not using setChartAttribute, and setting the subcaption in the JSON everytime the data changes instead. :unsure:

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Glad to know that you have managed to resolve your problem.

 

Happy FusionCharting!biggrin.gif

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