3

highcharts gets my hour time wrong

I'm from venezuela just in case. I doing a real time system where I get in my db the time,seconds and miliseconds like 10:39:09:2

I apply the strtotime($time) then I sended by json to charted

and in my highcharts i got in the

xAxis: {
  type: 'datetime',
  title: {
    text: 'Tiempo'
  }

the utc function is already false

Highcharts.setOptions({
  global: {
    useUTC: false
  }
});

and my function to get the json is

function requestData_Frecuencia() {
  $.ajax({
    url: 'Datos_Frecuencia.php',
    success: function (point) {
      var series = chart_Frecuencia.series[0],
        shift = series.data.length > 400;
      //add point
      chart_Frecuencia.series[0].addPoint(eval(point), true, shift);
      setTimeout(requestData_Frecuencia, 500);
    },
    cache: false
  });
}

PS. is been a while since I write in english so forgive me if I write something wrong o that isn't clear.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
rrey
  • 135
  • 1
  • 1
  • 5
  • So, what is wrong exactly? Is a point with data an hour ahead, behind, completely different? – wergeld Aug 20 '13 at 16:00
  • 1
    It is likely that the time your DB is storing is not using Venezuela's locale. – Kirk Backus Aug 20 '13 at 16:02
  • the DB is storing the time like Venezuelan time but when it gets to the highcharts, the time changes complety. I think because the data that I'm sending it contains miliseconds and highcharts supports until seconds (I think, I'm not sure ) – rrey Aug 22 '13 at 03:30

3 Answers3

0

You should check the raw values in the database. I know that MySQL stores dates in GMT. Not sure about the DB you are using, but the reason that this is done is:

GMT is an absolute time reference & doesn't change with the seasons.

You will have to convert the time to your locale, which is UTC–04:30

Have a look at: Convert date to another timezone in JavaScript

Community
  • 1
  • 1
Kirk Backus
  • 4,776
  • 4
  • 32
  • 52
  • I'm not quiet sure how to implemented. But the datetime I'm bringing from my db(which is pgsql) and sending in json is already in my timezone but when its gets to highcharts changed to another datetime. – rrey Aug 20 '13 at 20:13
0

Highcharts doesn't include timezones and only what you can do is disabling UTC,aas you have. THen you need to translate your data or use label formatter / tooltip formatter to display correct data.

Sebastian Bochan
  • 37,348
  • 3
  • 49
  • 75
  • how would you translate the data? – rrey Aug 22 '13 at 03:33
  • Add in formatter required value, for example: `formatter : function() { return Highcharts.dateFormat('%H:%M', this.value + 2 * 3600 * 1000); }` Where value after `+` is value you want to add translation. – Paweł Fus Aug 22 '13 at 11:41
0

I found out what I was doing wrong (found the answer here ). I used to get my time in php like:

while($r2 = pg_fetch_array($sth)) {
    $hora = $r2['hora'];
    $Frecuencia  = $r2['frecuencia'];
}
$x=strtotime($hora); 

I needed to multiplied by 1000 the time. I think, is because I need to suggested that date is in form of miliseconds (that is integer)

while($r2 = pg_fetch_array($sth)) {
    $hora = $r2['hora'];
    $Frecuencia  = $r2['frecuencia'];
}
$x=strtotime($hora)*1000; 

PD: thanks to everybody anyway for the suggestion and responses given. I really appreciated

Community
  • 1
  • 1
rrey
  • 135
  • 1
  • 1
  • 5