mysql - FusionCharts multiple array via SQL & PHP -


i attempting generate line graph using fusioncharts via sql query , php wrapper. cannot figure out how dataset graph , render it. assume require 2 sql queries , somehow load them array? attached code.

<?php    /* include `fusioncharts.php` file contains functions    embed charts. */       include("includes/fusioncharts.php");    /* following 4 code lines contain database connection information. alternatively, can move these code lines separate file , include file here. can modify code based on database connection. */       $hostdb = "127.0.1.1";  // mysql host     $userdb = "test";  // mysql username     $passdb = "test";  // mysql password     $namedb = "weather";  // mysql database name       // establish connection database     $dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);       /*render error message, avoid abrupt failure, if database connection parameters incorrect */     if ($dbhandle->connect_error) {        exit("there error connection: ".$dbhandle->connect_error);     }  ?>    <html>     <head>        <title>chart development</title>      <link  rel="stylesheet" type="text/css" href="css/style.css" />          <!-- need include following js file render chart.        when make own charts, make sure path js file correct.        else, javascript errors. -->          <script src="fusioncharts/fusioncharts.js"></script>    </head>       <body>        <?php             // form sql query returns results           $strquery = "select avg(temperature) avgtemp, avg(humidity) avghum, monthname (date) date data date between '2008-01-01' , '2016-01-01' group month (date) order month (date) asc";             // execute query, or else return error message.           $result = $dbhandle->query($strquery) or exit("error code ({$dbhandle->errno}): {$dbhandle->error}");               // form sql query returns results           $strquery2 = "select avg(humidity) avghum, monthname (date) date data date between '2008-01-01' , '2016-01-01' group month (date) order month (date) asc";             // execute query, or else return error message.           $result2 = $dbhandle->query($strquery2) or exit("error code ({$dbhandle->errno}): {$dbhandle->error}");               // if query returns valid response, prepare json string           if ($result) {              // `$arrdata` array holds chart attributes , data              $arrdata = array(                  "chart" => array(                    "caption" => "averages per month",                    "palettecolors" => "#6c7377",                    "bgcolor" => "#ffffff",                    "borderalpha"=> "20",                    "canvasborderalpha"=> "0",                    "useplotgradientcolor"=> "0",                    "plotborderalpha"=> "10",                    "showxaxisline"=> "1",                    "xaxislinecolor" => "#999999",                    "showvalues" => "0",                    "divlinecolor" => "#999999",                    "divlineisdashed" => "1",                    "showalternatehgridcolor" => "0"                    )                 );                $arrdata["data"] = array();        // push data array              while($row = mysqli_fetch_array($result)) {                 array_push($arrdata["data"], array(                    "label" => $row["date"],                    "value" => $row["avgtemp"]                    )                 );              }                /*json encode data retrieve string containing json representation of data in array. */                $jsonencodeddata = json_encode($arrdata);        /*create object column chart using fusioncharts php class constructor. syntax constructor ` fusioncharts("type of chart", "unique chart id", width of chart, height of chart, "div id render chart", "data format", "data source")`. because using json data render chart, data format `json`. variable `$jsonencodedata` holds json data chart, , passed value data source parameter of constructor.*/                $linechart = new fusioncharts("line", "myfirstchart" , 600, 300, "chart-1", "json", $jsonencodeddata);                // render chart              $linechart->render();                // close database connection              $dbhandle->close();           }          ?>          <div id="chart-1"><!-- fusion charts render here--></div>       </body>    </html>


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -