Skip to content
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

investigate best method of handling dates as x with various libraries #43

Open
timelyportfolio opened this issue Apr 24, 2013 · 2 comments

Comments

@timelyportfolio
Copy link
Contributor

Each javascript library seems to like dates as x in a different way. I wanted to document the behavior and then explore how rCharts should handle.

nvd3 fairly agnostic but rCharts provides x in a difficult form

.x(function(d) { return d[opts.x] })

which means we cannot parse here like this

 .x(function(d)  { return new Date(d)); }

or

 .x(function(d)  { return d3.time.format("%Y-%m-%d").parse(d); }

. Rather we format the date through a function call like this if we converted the date to milliseconds since 1970-01-01. We could really provide any date format and just adjust the function provided to the xAxis.

edhec.melt$date <- as.double(as.POSIXct(as.Date(edhec.melt$date),origin="1970-01-01")) * 1000
....

 chart.xAxis
  .tickFormat(function(d) {return d3.time.format("%Y-%m-%d")(new Date(d));})

polycharts likes %Y-%m-%d

The convert is easy, but polycharts does not seem to handle the date in the tooltip hover, only in the x axis.

managers.melt$date <- format(managers.melt$date,"%Y-%m-%d") 

Rickshaw likes seconds since 1970-01-01 or Unix time

rCharts implementation is not complete but Rickshaw seems to handle this universally.

edhec.melt$date <- as.double(as.POSIXct(as.Date(edhec.melt$date),origin="1970-01-01"))

Morris likes %Y-%m-%d like polycharts and seems to handle really well

managers.melt$date <- format(managers.melt$date,"%Y-%m-%d") 

I have not yet explored date handling in xCharts or Highcharts, but will as their support.

rCharts responsibility in handling dates

The question is

  1. Should rCharts automatically handle dates to prevent users from having to convert dates into each specific format?
@ramnathv
Copy link
Owner

Thanks for putting this together. I believe, rCharts should take the hassle out of handling dates for users, providing a simple way for them to choose the format.

@ramnathv
Copy link
Owner

It seems like toJSON accepts formatting arguments, which allow javascript dates to be preserved as milliseconds after 1970 (thanks to Ahmed Nagi). I need to investigate this and fix the default toJSON function in getPayload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants