jquery - Invalid dates in Highcharts with data loaded by JSON -
i cannot seem xaxis in highcharts display date data loaded via json. also, when hover on data point, label says "invalid date."
here php code used generate data:
function fetchlinechart() { $fetchdata = $this->db->query("select download, upload, date speed_entries order date desc"); while ($data = $fetchdata->fetch()) { $date = date("y, m, d", strtotime($data['date'])); $downloaddata[] = array('date.utc(' . $date . ')', (float)$data['download']); $uploaddata[] = array('date.utc(' . $date . ')', (float)$data['upload']); } $result = array('download' => $downloaddata, 'upload' => $uploaddata); echo json_encode($result); } and here jquery chart
$(document).ready(function() { var options = { chart: { renderto: 'linechart', type: 'line' }, title: { text: 'download / upload results' }, subtitle: { text: 'source: speedtest.net' }, yaxis: { title: { text: 'speed' }, plotlines: [{ value: 0, width: 1, color: '#808080' }] }, xaxis: { type: 'datetime' }, series: [{ name: 'download', linewidth: 2, marker: { radius: 2 }, data: [] }, { name: 'upload', data: [] }] }; $.getjson('class.speed.php?mode=linechart', null, function(json) { var downloads = json.download; var uploads = json.upload; options.series[0].data = downloads; options.series[1].data = uploads; chart = new highcharts.chart(options); }); }); everything else works, data lines displayed correctly. cannot figure out how make date work.
thanks
i might wrong here setting xaxis 'datetime', telling highcharts supply date in form of miliseconds (that integer) instead passing in string. why don't generate, linger suggested, miliseconds directly in php function?
$miliseconds = strtotime($data['date']) * 1000; $downloaddata[] = array($miliseconds, (float)$data['download'])
Comments
Post a Comment