-
Notifications
You must be signed in to change notification settings - Fork 57
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
Series data type #35
Comments
I looked at this in irb/pry: irb -rdate -rjson
>> DateTime.now.to_json
=> "\"2017-04-12T09:35:31+01:00\""
>> DateTime.now.iso8601
=> "2017-04-12T09:35:43+01:00" Is the problem the extra set of quotation marks in the json version? |
I'm using date types in data series without problem. Are you using the Chart.js library version that bundles Moment.js, or the version without it? I think this code will only work with the bundled version of the library, because all dates represented as strings will be parsed and converted by Moment.js. I'm guessing you aren't including the Moment.js library. Try changing If that solves the problem, perhaps it should be noted in the README.md that when using date/time series it's required to use the bundled version of the lib if you're not including it elsewhere in the project. I think Moment.js is a requirement of Chart.js (see: http://www.chartjs.org/docs/latest/axes/cartesian/time.html), and you shouldn't be using date/time series if you aren't including the Moment.js library on your project. The Chart.js library version without Moment.js included is provided in case you'd already included it on your project as a standalone library. |
@sbosio - I am having the same problem with a time series. I have to plot response time of an api over a period. I am using rails so I intuitively passed in Time object for x-axis. That did not seem to work. I also had to add code to the chart_helper
as I have time in epoch If you can share how you managed to get the ruby code working with date time, that would be extremely helpful. FYI @airblade When I pass in the x-axis as date time, I get the following in javascript where the Time object is presented as string.
If I get this working without my patch, I am happy to change the README to explain how to use date and time from ruby to work with chartjs through this gem. |
When I need to pass a Time object (as options for the graph, not for the data) I use the Time#iso8601 method in order to convert it into a string, as you can see in the uploaded image. |
@sbosio - Thanks for the input. I think I finally figured it out. It all depends on how one passes data. If you pass data as an array of pairs - [{x:ts, y:value},{x:ts, y:value}] where ts is timestamp then the library works.
|
I can't use a DateTime object in the series, but I needed it in xAxes as js date in a scatter chart.
I've solved it overwriting the helper, i've just added this:
when DateTime
"new Date('#{element.iso8601}')"
Thanks
The text was updated successfully, but these errors were encountered: