• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Highcharts Timezone Offset – solved

Q&A Forum › Category: ESP32 › Highcharts Timezone Offset – solved
0 Vote Up Vote Down
Sean Gell asked 4 years ago

Hi Sara and Rui
I’m working my through ESP Build Web server, and in the 3.3 Charts chapter I noticed the X axis is date and time but in UTC timezone. So I searched the Highcharts website and found this global modifier worked well to give me the correct timezone  on my charts:

Highcharts.setOptions({
    time: {
        timezoneOffset: -570 //my timezone is +09:30, however -570 is used
    }
});

Just thought you’d like to know in case you wanted to include in next update of the eBook.

I’m enjoying the book, thanks for your efforts.
Sean

6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Sean.
Thanks for sharing that.
I’ll definitely include that information in the next eBook update.
Regards,
Sara

0 Vote Up Vote Down
Roger Morin answered 3 years ago

Hi Sara, 
In Build_Web_Server 3.3 i find the proposed correction for a time zone not update, i tried it but it did not worked.
i joined the code for the scrpt-sensors.js file i used. I checked and my computer time is correct, and the browser i used is Google Chrome.
Any idea ?
Regards, 
Roger

Start your code here

// Get current sensor readings when the page loads  
window.addEventListener(‘load’, getReadings);
// Create Temperature Chart
Highcharts.setOptions({
  time: {
    timezoneOffset: -240 //Add your time zone offset here in minutes
 
  }
});
var chartT = new Highcharts.Chart({

  chart:{
    renderTo:’chart-temperature’
  },
  //time: {
    //timezone: ‘America/New_York’
  //},
  series: [
    {
      name: ‘BMP280’
    }
  ],
  title: {
    text: undefined
  },
  plotOptions: {
    line: {
      animation: false,
      dataLabels: {
        enabled:true
      }
    },
 
  xAxis: {
    type: ‘datetime’,
    dateTimeLabelFormats: { second: ‘%H:%M:%S’ }
  },
  yAxis: {
    title: {
      text:’Temperature Celsius Degrees’
    }
  },
  credits: {
    enabled:false
  }
 }});
 
// Create Pressure Chart

var chartP = new Highcharts.Chart({
  chart:{
    renderTo:’chart-pressure’
  },
  //time: {
   // timezone: ‘America/New_York’
  //},
  series: [{
    name: ‘BMP280’
  }],

  title: {
    text: undefined
  },    
  plotOptions: {
    line: {
      animation: false,
      dataLabels: {
        enabled:true
      }
    },
  series: {
      color:’#50b8b4′
    }
  },
  xAxis: {
    type: ‘datetime’,
    dateTimeLabelFormats: { second: ‘%H:%M:%S’ }
  },
  yAxis: {
    title: {
      text:’Pressure hPa ‘
    }
  },
  credits: {
    enabled:false
  }
});

//Plot temperature in the temperature chart
function plotTemperature(value) {
  var x = (new Date()).getTime()
  var y = Number(value);
  if(chartT.series[0].data.length > 40) {
    chartT.series[0].addPoint([x, y], true, true, true);
  } else {
    chartT.series[0].addPoint([x, y], true, false, true);
  }
}

//Plot pressure in the pressure chart
function plotPressure(value) {
  var x = (new Date()).getTime()
  var y = Number(value);
  if(chartP.series[0].data.length > 40) {
    chartP.series[0].addPoint([x, y], true, true, true);
  } else {
    chartP.series[0].addPoint([x, y], true, false, true);
  }
}

// Function to get current readings on the webpage when it loads for the first time
function getReadings(){
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      var myObj = JSON.parse(this.responseText);
      console.log(myObj);
      var temp = myObj.temperature;
      var press = myObj.pressure;
      plotTemperature(temp);
      plotPressure(press);
    }
  };
  xhr.open(“GET”, “/readings”, true);
  xhr.send();
}

if (!!window.EventSource) {
  var source = new EventSource(‘/events’);
 
  source.addEventListener(‘open’, function(e) {
    console.log(“Events Connected”);
  }, false);

  source.addEventListener(‘error’, function(e) {
    if (e.target.readyState != EventSource.OPEN) {
      console.log(“Events Disconnected”);
    }
  }, false);
 
  source.addEventListener(‘message’, function(e) {
    console.log(“message”, e.data);
  }, false);
 
  source.addEventListener(‘new_readings’, function(e) {
    console.log(“new_readings”, e.data);
    var myObj = JSON.parse(e.data);
    console.log(myObj);
    plotTemperature(myObj.temperature);
    plotPressure(myObj.pressure);
  }, false);
}

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
 
Yes.
I recently found out that by default, the charts will show the time in UTC. If you want it to display in your timezone, you must set the useUTC parameter (which is a time parameter) as false:

time:{
  useUTC: false
},

So, add that when creating the chart as follows:

var chart = new Highcharts.Chart({
time:{
useUTC: false
},
(...)

To learn more about this property, check this link on the documentation:

  • https://api.highcharts.com/highcharts/time.useUTC

 
I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
Roger Wilson answered 2 years ago

Hi Sara,
I adjusted my Highcharts for time zone successfully but daylight saving offset is not accounted for. I’m UTC +10hrs but currently +11hrs with daylight saving active. I can’t see anything on the Highcharts webpage referencing a daylight saving offset so unless I’ve missed it I guess I’d need another way to do that if I wanted to, perhaps using ntp somehow? Any solutions/advice?

0 Vote Up Vote Down
Roger Wilson answered 2 years ago

Hi Sara,
I didn’t appreciate that your previous answer addressed daylight saving time as well as timezone. I just tried it and it worked so apologies for unnecessary question. 

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
Don’t worry.
I’ll mark this issue as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.