1

I wanted to show the month for a specific date in my google chart I have this JSON(livedata.php) code:

$data_points = array();
while($row = mysqli_fetch_array($result)){      
$monthNum = date('m',strtotime($row['time_stamp']));
$DayNum = date('d', strtotime($row['time_stamp']));     
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');
if($monthNum == "7"){
      if (array_key_exists($DayNum, $data_points)) {
      $data_points[$DayNum]->ph += $row['ph'];
      $data_points[$DayNum]->moist += $row['moist'];
          }else{
        $data_points[$DayNum]->ts = $DayNum;
      $data_points[$DayNum]->ph = $row['ph'];
      $data_points[$DayNum]->moist = $row['moist'];   
  }
} }
echo json_encode(array_values($data_points));  

That Shows the following Output:

[{"ts":"29","ph":"8","moist":"2"},{"ts":"28","ph":40,"moist":35},{"ts":"27","ph":16,"moist":8}]

the output above means: the ph value on a specific date from the month of July.I wanted to show ts: Month day but my chart shows nothing

Now to output a graph I have this kind of javascript code and chart:

google.charts.load('current', {
    callback: drawChart,
    packages: ['corechart']
    });

 function drawChart() {
     var jsonData = $.ajax({
     url: 'livedata.php',
     dataType: 'json',}).done(function (results) {

     var data = new google.visualization.DataTable();

     data.addColumn('date', 'time_stamp');
     data.addColumn('number', 'ph');
     data.addColumn('number', 'moist');


     $.each(results, function (i, row) {
     var dbdate = new Date();

     data.addRow([
     new Date(dbdate.getFullYear(), dbdate.getMonth(), row.ts),
     parseFloat(row.ph),
     parseFloat(row.moist)]);});

     var chart = new google.visualization.LineChart($('#chart').get(0));

     chart.draw(data, {
     title: 'Soil Analysis'});});
}

having an output below: enter image description here

I am wondering why it happened to be september.I guess it is all because of the date() from my javascript.What should i need to do?Please Help!!I am really a newbie in terms of chart and web visualization.I am asking for Help.

1
  • I'm not completely sure about what I found, but your dbdate initialization might be causing it: the constructor Date() called without any argument creates a Date with the current time in your system. Check this out Commented Sep 5, 2017 at 20:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.