Sign in to follow this  
LAIRONS

Using DB to make multi line chart with different X value

Recommended Posts

So, i have DB like these :

+----------+------------+-------+
| Time       | Date      | A0 |
+----------+------------+-------+
| 17:00:00 | 2015-06-23 | 100 |
| 17:05:00 | 2015-06-23 | 120 |
| 17:10:00 | 2015-06-23 | 200 |
| 17:00:00 | 2015-06-24 | 200 |
| 17:05:00 | 2015-06-24 | 190 |
| 17:10:00 | 2015-06-24 | 200 |
| 08:00:00 | 2015-06-25 | 90  |
+----------+------------+-------+

and I use these code :

<?php

      //We have included ../Includes/FusionCharts.php, which contains functions
      //to help us easily embed the charts.
      include("class/Includes/FusionCharts.php");
 include("class/Includes/DBConn.php");
      ?>
      <HTML>
         <HEAD>
        <TITLE> FusionCharts XT - </TITLE>
        <SCRIPT LANGUAGE="Javascript" SRC="fusioncharts/fusioncharts.js"></SCRIPT>
<SCRIPT LANGUAGE="Javascript" SRC="fusioncharts/themes/fusioncharts.theme.fint.js"></SCRIPT>
     </HEAD>
     <BODY>
 
<?php
                        $link = connectToDB();
 
 
                      
   $strQueryCategories = "select distinct Time from input where Date between '2015-06-23' and '2015-06-27' order by Time";
 
 
                        
                        $resultCategories = mysql_query($strQueryCategories) or die(mysql_error());
 
                      
$strQueryData = "select * from input where Date between '2015-06-23' and '2015-06-27'
";
 
                      
                        $resultData = mysql_query($strQueryData) or die(mysql_error());
 
                       
                        $strXML = "<chart legendPostion='' caption='Konsentrasi CO2' subCaption='By Quantity' xAxisName='Time' yAxisName='Concentration (ppm)' showValues='0' formatNumberScale='0' rotateValues='1' theme='fint'>";
 
                        $strXML .= buildCategories ($resultCategories, "Time");
 
                       
                        $strXML .= buildDatasets ( $resultData, "A0", "Date");
 
                       
                        $strXML .= "</chart>";
 
 
echo renderChart("MSLine", "", $strXML, "FactorySum", 600, 300, false, true);
 
 
                      
                        mysql_free_result($resultCategories);
                        mysql_free_result($resultData);
                        mysql_close($link);
 
                     function buildCategories ( $result, $labelField ) {
                            $strXML = "";
                            if ($result) {
                                $strXML = "<categories>";
                                while($ors = mysql_fetch_array($result)) {
                                    $strXML .= "<category label='" . $ors[$labelField]. "'/>";
                                }
                                $strXML .= "</categories>";
                            }
                            return $strXML;
                        }
 
                      
 
 
                        function buildDatasets ($result, $valueField, $controlBreak ) { 
                            $strXML = "";
                            if ($result) {
 
                                $controlBreakValue ="";
                                     
                                while( $ors = mysql_fetch_array($result) ) {
 
echo" ";
 
                                    if( $controlBreakValue != $ors[$controlBreak] ) {
                                        $controlBreakValue =  $ors[$controlBreak];
                                        $strXML .= ( $strXML =="" ? "" : "</dataset>") . ( "<dataset seriesName='" . $controlBreakValue . "'>" ) ;
                                    }
                                  
   $strXML .= "<set value='" . $ors[$valueField] . "'/>";
 
                                }
                                $strXML .= "</dataset>";
                            }
 
                            return $strXML;
 
                        }
?>
 
        
  </BODY>
</HTML>
 
But what I get is a chart with false value. the 1st value of A0 data at 2015-06-23 and 2015-06-24 are at 08:00:00 instead of 17:00:00, and so goes on for the other data. Please someone help me So the only data at 08:00:00 only 2015-06-25 data

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