Sign in to follow this  
adumas

Multiple Dynamic chart generation single page

Recommended Posts

I am trying to dynamically place charts on one page. When I run the following code, only the last date is creating/displaying a chart. Other dates are not showing up. It seems as though the xml is being rewritten/purged and chart destroyed with each succeeding loop. I'm including all of the code - please indicate what I need to change.  I will greatly appreciate the aid.

 

_Temp_Loop.php
<?php
   //Database include 
   include("../phpmysql/DBConn.php");
  
  //Connect to the DB
  $link = connectToDB();

   //Fetch all event dates ( will produce 3 dates, 2011-01-01
  $dateQuery = "select distinct date_format(EventDate, '%Y-%m-%d') as EventDate
  	from Micro_EventLog
group by date_format(EventDate, '%Y-%m-%d')
order by date_format(EventDate, '%Y-%m-%d')"; 

  $getDates = mysql_query($dateQuery) or die(mysql_error());
 
  //contains functions to easily embed charts.
  include("../phpmysql/FusionCharts.php");
?>
<HTML>
<HEAD>
  <TITLE> Display latest Temperature Results</TITLE>
  <SCRIPT LANGUAGE="Javascript" SRC="../phpmysql/FusionCharts.js"></SCRIPT>
</HEAD>
<BODY>
<!--- -------------------------------------------------------------------------- 
 default main page
--------------------------------------------------------------------------- --->
<input type="Button" value="Finished" onclick=location.href='../phpmysql/ViewSensorLog.php'> 

<?php 
 
   //Iterate through each temp record (3 of them for now... )
  if ($getDates) {
  while($orsDate = mysql_fetch_array($getDates)) {

    $newstring = "../phpmysql/_TempData_Loop.php?animate=1&EventDate=" . $orsDate['EventDate'];
  echo($newstring); 
   
    //NOTE: It's necessary to encode the dataURL if you've added parameters to it
     $strDataURL = encodeDataURL($newstring);
 ?>
 <br>
 <br>
 <?php 
    //Create the chart - dataURL as strDataURL
     echo renderChart("../phpmysql/Charts/Line.swf", $strDataURL, "", "Temperature", 500, 300, false, false);
  ?>
 <br>
 <br>
 <?php 
  }
  }
  mysql_free_result($getDates);
  mysql_close($link);

?>
</form>
</BODY>
</HTML>
********************************************************
********************************************************
********************************************************
_TempData_Loop.php
 <?php
  //Database include 
  include("../phpmysql/DBConn.php");

  //Connect to the DB
  $link = connectToDB();
   //Default.php has passed us a property animate. We request that.
  $animateChart = $_GET['animate'];

  $EventDate = $_GET['EventDate'];
   //Set default value of 1
  if ($animateChart=="")
  $animateChart = "1";
   //$strXML will be used to store the entire XML document generated
  //Generate the chart element
  $strXML = "<chart 
adjustDiv    = '0' 
anchorRadius  = '1'
baseFontSize   = '10'  
canvasPadding  = '0' 
  	caption	= 'Local Temperature Report'  
chartheight   = '900'  
chartwidth   = '900' 
chartTopMargin  = '0'
chartBottomMargin = '0'
connectNullData  = '1' 
formatNumberScale = '0' 
labelDisplay  = 'WRAP'
labelStep    = '60'    
valueStep    = '60'	 
lineDashGap   = '0'   
numVDivLines  = '11'  
numberSuffix   = '' 
numVDivLines  = '11'  
rotateLabels  = '1'
rotateValues  = '1'
scaleto	= '100'
showBorder   = '1' 
showValues   = '0'   
  	subCaption   = 'By Time'  
yaxisname    = 'Readings'	 
yAxisMaxValue    = '70'   
yAxisMinValue    = '30'  
yAxisName   = 'Degrees'
yAxisValuesStep  = '1'    
animation=' " . $animateChart . "'>";
   //Fetch all factory records
  $strQuery = "select avg(SensorValue) as SensorValue,
  	    date_format(EventDate, '%Y-%m-%d %h') as EventDate 
  	from Micro_EventLog 
where date_format(EventDate, '%Y-%m-%d') = '$EventDate'
group by date_format(EventDate, '%Y-%m-%d %h')
order by date_format(EventDate, '%Y-%m-%d %h')  ";
  $result = mysql_query($strQuery) or die(mysql_error());
   //Iterate through each hourly temp
  if ($result) {
  while($ors = mysql_fetch_array($result)) {
	 //Generate <set label='..' value='..' />
	 $strXML .= "<set label='" . $ors['EventDate'] . "' value='" . $ors['SensorValue'] . "' />";
	 //free the resultset
	 //mysql_free_result($result);
  }
  }
  mysql_free_result($result);
  mysql_close($link);
   //Finally, close <chart> element
  $strXML .= "</chart>";
   //Set Proper output content-type
  header('Content-type: text/xml');
   //Just write out the XML data
  //NOTE THAT THIS PAGE DOESN'T CONTAIN ANY HTML TAG, WHATSOEVER
  echo $strXML;
?>

Share this post


Link to post
Share on other sites

Hi.. I don't see how that can help, but here it is below...

I'm also including a picture of the output which shows only 1 graph (for the

last date range)... 4 graphs should appear b0e1760d-7483-4491-aa23-7f07.jpg

*******************************************************

<code>

Info: Chart loaded and initialized.

Initial Width: 500

Initial Height: 300

Scale Mode: noScale

Debug Mode: Yes

Application Message Language: EN

Version: 3.0.7

Chart Type: Single Series 2D Line Chart

Chart Objects:

BACKGROUND

CANVAS

CAPTION

SUBCAPTION

YAXISNAME

XAXISNAME

DIVLINES

VDIVLINES

YAXISVALUES

HGRID

VGRID

DATALABELS

DATAVALUES

TRENDLINES

TRENDVALUES

DATAPLOT

ANCHORS

TOOLTIP

VLINES

INFO: XML Data provided using dataURL method.

dataURL provided: ../phpmysql/_TempData_Loop.php?animate=1&EventDate=2009-11-21

dataURL invoked: ../phpmysql/_TempData_Loop.php?animate=1&EventDate=2009-11-21&FCTime=178

XML Data: <chart adjustDiv="0" anchorRadius="1" baseFontSize="10" canvasPadding="10" caption="Local Temperature Report" chartheight="900" chartwidth="900" chartLeftMargin="10" chartRightMargin="10" chartTopMargin="0" chartBottomMargin="0" connectNullData="1" decimals="2" formatNumberScale="0" labelDisplay="WRAP" labelStep="1" valueStep="1" lineDashGap="0" numberSuffix="" numVDivLines="11" rotateLabels="1" rotateValues="1" scaleto="100" showBorder="1" showValues="1" subCaption="By Time" yaxisname="Readings" yAxisMaxValue="70" yAxisMinValue="20" yAxisName="Degrees" yAxisValuesStep="1" animation=" 1"><set label="2009-11-21 01" value="45.711506849315" /><set label="2009-11-21 02" value="45.736923076923" /><set label="2009-11-21 03" value="45.794068965517" /><set label="2009-11-21 04" value="45.733356164384" /><set label="2009-11-21 05" value="45.699452054795" /><set label="2009-11-21 06" value="45.694178082192" /><set label="2009-11-21 07" value="45.569523809524" /><set label="2009-11-21 08" value="45.932827586207" /><set label="2009-11-21 09" value="47.404081632653" /><set label="2009-11-21 10" value="49.311164383562" /><set label="2009-11-21 11" value="51.115454545455" /><set label="2009-11-21 12" value="45.686643835616" /></chart>

 

</code>

Share this post


Link to post
Share on other sites

Hi,

 

 

 

Could you please try once trying the same in Firefox ?

 

 

 

If it works in Firefox, it seems that your are trying to generate the chart with same chartId, i.e. "Temperature"

 

 

 

 

 

echo renderChart("../phpmysql/Charts/Line.swf", $strDataURL, "", "Temperature", 500, 300, false, false);

 

 

 

 

 

Please generate unique values like "Temperature1", "Temperature2", "Temperature3" ...

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