Home › forums › Chart Support › dateTime stamp time zone
Tagged: DateTime, timezone
Hello, following the instructions on https://canvasjs.com/docs/charts/basics-of-creating-html5-chart/date-time-axis/
I have datapoints that use a dateTime stamp in milliseconds in UTC. But when I put them into the chart, it comes out as my local time zone along the x-axis. How can I set it so the x-axis stays as UTC?
Also if you like to display time in a particular timezone, you can use the toLocaleString() method to convert a Date object to a string, using locale settings. You can output dates that are in UTC or local time to a specific timezone by passing timeZone option to toLocaleString().
Hello, can you give an example based on my jsfiddle?
I tried applying toUTCString to the x datapoints and it didn’t work. For example, in a datapoint pair, “x”: (new Date(1601006400003)).toUTCString() didn’t output anything.
I think I was able to get what I wanted by using labelFormatter and combining it with toLocaleString. Updated example: https://jsfiddle.net/h1movjbe/1/
Glad it worked for you. :)
You can further improve the solution by formatting the date and time values in toolTip using the contentFormatter, please take a look at this updated JSFiddle for an example on the same.
Hello, I have interval set to 1 day, but the tick marks still have an interval of every local day instead of UTC day. How can I change the interval tick to occur on every UTC midnight?
Displaying labels at a specific position(say every midnight) on the axes depends upon the very first label that is rendered, subsequent labels are just rendered at a defined interval(auto-calculated/user-defined) from there. As of now, we do not have control over the starting label on the axes and so it is not possible to achieve the above requirement.
You must be logged in to reply to this topic.