-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Milliseconds data detection and plotting #7
Comments
Hi, Apologies for the delay. After guidance from the dygraph users group there is a working jfiddle of using millisecond plotting: So to accomplish this in R, I think we'd first need to convert POSIXlt objects to milliseconds since epoch and enclose within "#! !#". As a reference here is an example of millisecond plotting in highcharts: require(rCharts);require(xts)
npoints<-500
Data_xts=xts(1:npoints, as.POSIXlt(1366039619, tz="GMT", origin="1970-01-01") + round(runif(npoints,1,50)))
names(Data_xts)<-'RandomData'
DataDF=data.frame(Date=index(Data_xts),coredata(Data_xts$RandomData))
DataDF$Date=paste("#!", as.numeric(strptime((DataDF$Date), format="%Y-%m-%d %H:%M:%OS"))*1000, "!#")
HCGraph <- Highcharts$new()
HCGraph$yAxis(list(title = list(text = 'Data1') ) )
HCGraph$series(data = toJSONArray2(DataDF[,c('Date','RandomData')], json = F, names = F),enableMouseTracking=TRUE,shadow=FALSE,name = "Data1",type = "line")
HCGraph$xAxis(type = "datetime"); HCGraph$chart(zoomType = "x")
HCGraph$plotOptions(column=list(animation=FALSE),shadow=FALSE,line=list(marker=list(enabled=FALSE)));
HCGraph Then based on the jfiddle we need to ass custom axisLabelFormatter and valueFormatter functions. myChart$setOpts(axisLabelFormatter = "#! function (d, gran) {
return Dygraph.zeropad(d.getHours()) + ":" + Dygraph.zeropad(d.getMinutes()) + ":" + Dygraph.zeropad(d.getSeconds()) + "." + Dygraph.zeropad(d.getMilliseconds());
} !#")
myChart$setOpts(valueFormatter = "#! function (ms) {
var d = new Date(ms);
return Dygraph.zeropad(d.getHours()) + ":" + Dygraph.zeropad(d.getMinutes()) + ":" + Dygraph.zeropad(d.getSeconds()) + "." + Dygraph.zeropad(d.getMilliseconds());
}!#") Unforuntately, I was unable to get this to work - could you take a look please. Cheers |
Thanks for catching the double versus single quotes parsing error.
I confirm your suggested changes work with the exception of how the data is passed to dygraph.
Result in POSIXlt complaining about the format - so I assume it is still trying to obtain a date object. Where passing in the xts object directly worked with issue
Out of interest how do you plan to automatically detect data frequency? |
Yes sorry, was typing that fast, I meant
Don't know yet, focusing on other parts for the time being. Any suggestions, contributions welcome! Feel free to fork, develop and I will make sure to answer your specific questions, review and accept your pull request :) |
Sure, I'll fork and have a go. |
Hi I tried your code in order to display milliseconds in a dygraph plot but when I run this code:
I got this error:
Do you know what to fix it? |
@Haycen please note that the active development has moved to rstudio/dygraphs repository and they track the sub-second handling issue. |
Detect the dataset resolution and automagically switch between the parser modes.
JavaScript millisecond parsing here (WIP) : danielkrizian/dygraphs#12
Other resources:
https://groups.google.com/forum/#!topic/dygraphs-users/qAKQndJvkRE
http://dygraphs.com/data.html
The text was updated successfully, but these errors were encountered: