I am using jqPlot with DateAxisRenderer to display graphs of various functions of time. I want to make the graph communicate with other modules of the application, that also deal with time data (but not with graphs). To accomplish this, all modules will write and read the same time variable (so they always display data for the same instant). If any module sets the variable, the others have to react accordingly.
Example: User enters time in a readable format, what causes a custom tick to be displayed in the graph on the proper x coordinate.
However, to implement this, I need to convert between three representations of time
- any human-readable format (or the javascript
Dateobject as its encapsulation) - the timestamp used internally by
jqPlotto represent time xcoordinate (in pixels) in the graph
I know that DateAxisRenderer can display the timestamp in a customizable human-readable format, as it does so when it renders the x-axis. I know that after clicking in the graph, I get the timestamp in the event information (together with the x coordinate). But my question is: How to do these conversions explicitly?.
Date <–> human-readable formats
Datejs works well for this. For example:
Date <–> jqPlot timestamp
The timestamp used internally in jqPlot is simply the Unix time in milliseconds:
Date <–> x coordinate (in pixels)
Assuming your x-axis is linear you can determine the value of a point on the x-axis like this (fill in your own values):
At the time of writing this post, here is a list of the axis names: