日期 <--> 人类可读的格式
Datejs很适合这个。例如:
var date = Date.parse('February 20th 1973');
var date = Date.parse('next thursday');
// Now let's convert a date into a human-readable string
var dateString = date.toString('dddd, MMMM d, yyyy');
日期 <--> jqPlot 时间戳
jqPlot 内部使用的时间戳只是Unix 时间(以毫秒为单位):
var exampleTimestamp = 1345671839000;
var date = new Date(exampleTimestamp);
// Now let's convert a date into a timestamp
var jqPlotTimestamp = date.getTime();
日期 <--> x 坐标(以像素为单位)
假设您的 x 轴是线性的,您可以像这样确定 x 轴上一个点的值(填写您自己的值):
var myPlot = jqplot(...);
var xAxis = myPlot.axes.xaxis;
var MARGIN_LEFT = 15; // Pixels from [left edge of chart --> minimum X value]
var pixelRange = 300; // Pixels from [min X value --> max X value]
var timeRange = xAxis.max - xAxis.min;
var time; // This will be our answer in the chart's units
time = xAxis.min + timeRange * (xCoordinate - MARGIN_LEFT) / pixelRange;
var timeInMillis = ... ; // Convert the X-Axis unit of time into millis
var date = new Date(timeInMillis);
// Now let's convert a date into an x coordinate
timeInMillis = date.getTime();
time = ...; // Convert millis into X-Axis unit of time
var x = MARGIN_LEFT + pixelRange * (time - xAxis.min) / timeRange;
在撰写本文时,这里是轴名称列表:
['yMidAxis', 'xaxis', 'yaxis', 'x2axis', 'y2axis', 'y3axis', 'y4axis', 'y5axis', 'y6axis', 'y7axis', 'y8axis', 'y9axis'];