I have to display some sensors data using highcharts and
I’m using YII as php framework.
I store the time in mysql (v5.6) as timestamp(3) I need the millisecond fraction
and I want to use it because almost of my data are in one second or 2
my controller give me as output
["2012-12-01 15:00:00.070",45]
but this point is not shown in my chart , and the ajax request is made just one time
I get the error with firebug at the level of ” var series = chart.series[0], ”
I don’t know if the problem is in my highchart code or in the time format
I don’t know also how to use the Dateparse inside my code after receiving the point
please help !
function requestData() {
$.ajax ({
type:"get" ,
url: "<?php echo CController::createUrl('beam/GetSensorsDataLive') ?>",
data: {"beamId" : "<?php echo $modelBeam['poutre_id'] ?>" },
dataType: "json",
success: function(response,point) {
var series = chart.series[0], //// error here
shift = series.data.length > 20;// shift if the series is longer than 20
chart.series[0].addPoint( point,true, false); // add the point
setTimeout(requestData, 1000); // call it again after one second
},
cache: false
});
}
$(document).ready(function() {
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'graph',
type: 'spline',
events: {
load: requestData
}
},
xAxis: {
type: 'datetime',
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%H:%M:%S:%m', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
series: [{
name: 'Live Data From sensor <?php echo $modelBeam['poutre_id'] ;?> ',
data:[]
}]
});
});
Your data x should be JS timestamp in miliseconds, also you can parse your data from php and use Date.UTC() function.