Mysql
 sql >> Base de données >  >> RDS >> Mysql

Google trace l'axe des x continu à partir du tableau php

L'erreur est générée car les valeurs de la première colonne doivent être réelles date valeurs.

Essayez de remplacer...

{"c":[{"v":"04-10-2015"},{"v":0.4}]}

Avec...

{"c":[{"v":new Date("10/04/2015")},{"v":0.4}]}

Utilisation...

$date1 = date_create_from_format('Y-m-d H:i:s', $row['Date']);
$date2 = "new Date(\"".date("m",$date1)."/".date("d",$date1)."/".date("Y",$date1)."\")";
$temp[] = array('v' => (string) $date2);

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

function drawChart() {
  var json = {
    "cols":[
      {"label":"Reading Date","type":"date"},
      {"label":"Cl Reading(mg\/l) ","type":"number"}
    ],
    "rows":[
      {"c":[{"v":new Date("10/04/2015")},{"v":0.4}]},
      {"c":[{"v":new Date("11/04/2015")},{"v":0.45}]},
      {"c":[{"v":new Date("12/04/2015")},{"v":0.9}]},
      {"c":[{"v":new Date("01/04/2016")},{"v":0.5}]},
      {"c":[{"v":new Date("02/04/2016")},{"v":0.43}]},
      {"c":[{"v":new Date("02/18/2016")},{"v":0.6}]}
    ]
  }

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

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, {});
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>