javascript - Php and Html chart using Canvas.js using mysql database -


i trying fetch data mysql database , plot line graph using canvas.js way.....i want know how pass values have fetched database datapoints: x , y values....i;e..x contain time , y contains temperature.i trying plot time vs temperature graph here..

i have received these 2 data values database in php using code.

$sql1 = "select time sdata order id desc limit 10;"; $response1 = mysqli_query($connect, $sql1) or die(mysqli_error($connect)); while($row1 = mysqli_fetch_all($response1)){     $r1[]= $row1; }  $sql2 = "select temperature sdata order id desc limit 10;"; $response2 = mysqli_query($connect, $sql2) or die(mysqli_error($connect)); while($row2 = mysqli_fetch_all($response2)){     $r2[]= $row2; } 

here when give echo , see r1 , r2 values able see database values....

--these datetime values database:

[[["8/30/2016 9:37"],["8/30/2016 9:33"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:31"],["8/30/2016 9:31"],["8/30/2016 9:31"]]]

--these temperature values database:

[[[25],[25],[28.91],[28.82],[28.84],[28.91],[29.05],[29.05],[28.92],[29.11]]]

now want pass these varaibles datapoints: x , y shown in below code:

<script type="text/javascript"> window.onload = function() {      var chart = new canvasjs.chart("chartcontainer", {         title: {             text: "line chart"         },         axisx: {              interval: 5,             title: "time",             valueformatstring: "hh:mm tt",          },         axisy: {              interval: 20,             title: "temp"          },         data: [{             type: "line",             datapoints: ???????????(how pass r1 , r2 values here x , y respectively give me line chart question)          }]     });     chart.render();  } </script> 

plz me in this....

you need parse data in format canvasjs accepts. check code below

$r1=[[["8/30/2016 9:37"],["8/30/2016 9:33"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:32"],["8/30/2016 9:31"],["8/30/2016 9:31"],["8/30/2016 9:31"]]];  $r2=[[[25],[25],[28.91],[28.82],[28.84],[28.91],[29.05],[29.05],[28.92],[29.11]]]; $datapoints=array(); for($i=0;$i<count($r1[0]);$i++){     array_push($datapoints,array('x'=> strtotime($r1[0][$i][0])*1000,'y'=>$r2[0][$i][0])); }  var chart = new canvasjs.chart("chartcontainer", { . . datapoints: <?php echo json_encode($datapoints); ?> // edited . . }); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -