How do I display the formatted timestamp in a hoverable data point in a Flot line chart?
Currently my line graph displays the properly formatted timestamp from the JSON data se开发者_开发百科t along the x-axis.
example:
xaxis: { mode:"time", timeformat: "%y/%m/%d %H:%M:%S%p"}
The output is something like:
2010/12/6 05:32:32pm
I also have my data points hoverable.
When I hover over the data points it displays
(1291656755000, 1368ms)
Where 1291656755000 is the original time stamp in milliseconds.
I'd like it where 1291656755000 is displayed as 2010/12/6 05:32:32pm like it is in the x-axis when I hover over the data point.
In the code where you generate the tooltip, call the flot formatDate function before passing the value to the tooltip function:
$.plot.formatDate = function(d, fmt, monthNames)
Where d is the date, fmt is your format string, and monthNames is optional.
You would call it like this:
var formattedDateString = $.plot.formatDate(d, "%y/%m/%d %H:%M:%S%p");
If this doesn't make sense, post your tooltip code.
精彩评论