javascript - PHP Chart Js Load Mysql and Interface -


this source viewgraph.php

        <?php                $datesgraph = array();             $moneyss = array();             $sql = "select right(datetransaksi,2) dates, sum(allmoney ) money view_resume_transaksi                      datetransaksi between '20160401' , '20160420' group datetransaksi order datetransaksi asc" ;                $hasil=sqlsrv_query($conn, $sql) or die($sql . "<br>" .print_r( sqlsrv_errors(), true)) ;                 while($row = sqlsrv_fetch_array($hasil)){                                         $moneyss[$row[0]] = (int)$row[1];                                          $datesgraph[]=$row['tgl'];                                          $moneyss[]=$row['money'];                                      }  ?>  <script>     var randomscalingfactor = function(){ return math.round(math.random()*100)};     var linechartdata = {          labels : <?=json_encode($datesgraph);?>,         datasets : [             {                 label: "my second dataset",                 fillcolor : "rgba(151,187,205,0.2)",                 strokecolor : "rgba(151,187,205,1)",                 pointcolor : "rgba(151,187,205,1)",                 pointstrokecolor : "#fff",                 pointhighlightfill : "#fff",                 pointhighlightstroke : "rgba(151,187,205,1)",             data : <?=json_encode($moneyss);?>             }         ]     }     window.onload = function(){     showgrafik(); }  function showgrafik(){     var ctx = document.getelementbyid("canvas").getcontext("2d");         window.myline = new chart(ctx).line(linechartdata, {             responsive: true         }); } 

and have in bottom

<td>    <label align="left">choose date</label>    <input type='text' id='date1_g' name='date1_g' size='12' value="<?php echo date('d-m-y');?> ">until <input type='text' id='date2_g' name='date2_g' size='12' value="<?php echo date('d-m-y');?> ">   </td>  <div style="width:80%"><canvas id="canvas" height="450" width="600"></canvas> </div> 

this succesfully load data mysql... don't know, if user change date , date mysql , view graph. mean if proses > choose date -> send data using ajax -> viewing graph. proses > load .php -> viewing graph (because sql using not parameters interface).

please me, want display graph using ajax... thank's attention.

make function in javascript accept datefromand dateto parameters call in sql query in php via ajax. this..

var path_to_php_file = 'getdate.php';    function loadchartbydate(datefrom,dateto){     $.ajax(){       url: path_to_php_file,       type: 'post',       datatype: 'json',       data: {'datefrom': datefrom, 'dateto': dateto},       success: function(data){         //display data in chart         //add under success callback function         var randomscalingfactor = function(){ return                               math.round(math.random()*100)};         var linechartdata = {          labels : <?=json_encode($datesgraph);?>,            datasets : [               {                  label: "my second dataset",                  fillcolor : "rgba(151,187,205,0.2)",                  strokecolor : "rgba(151,187,205,1)",                  pointcolor : "rgba(151,187,205,1)",                  pointstrokecolor : "#fff",                  pointhighlightfill : "#fff",                  pointhighlightstroke : "rgba(151,187,205,1)",                   data : <?=json_encode($moneyss);?>               }             ]           }        window.onload = function(){               var ctx = document.getelementbyid("canvas").getcontext("2d");               window.myline = new chart(ctx).line(linechartdata, {                              responsive: true               });        }        },       error: function(err){         console.log(err.responsetext);         }     }  }  

Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -