Search code examples
rhighchartsrcharts

How to get the correct the date-time format for highcharts in R (using rcharts)


I currently have a dataframe called minuteDataPlot in which I am trying to plot with highcharts in rCharts

users      timestamp
1276   2015-10-03 09:00:00
1292   2015-10-03 09:01:00
1306   2014-10-03 09:02:00

Here is my code:

a <- hPlot(users ~ timestamp, data = minuteDataPlot,
           type = 'spline', title = 'SBK Users per Minute', subtitle = 'Real-Time')
a$global(useUTC = FALSE)
a$xAxis(type='datetime')
a

The class for minuteDataPlot$timestampis POSIXlt. My result is

highchart attempt with mydatetime

You can see that the x-axis does not reflect my timestamp data. I would expect something something similar to my timestamps (e.g 2015-10-03 09:00:00).

I have tried using numeric class as well, but I get the same result. Any help would be grand. I have checked the highcharts documentation as well of course and I can't seem to find any help there.


Solution

  • I understand properly now you have to convert to miliseconds. Here is the code which worked for me:

    minuteDataPlot2 <- transform(minuteDataPlot,
    timestamp2 = as.numeric(as.POSIXct(timestamp))*1000)