我的图表从服务器获取数据,时间服务器 * 1000 用于转换为时间 js。这是我的图表
http://awesomescreenshot.com/03f1ft5k72
点与列日不符。我必须对每个值 + 25 000 000 以显示它匹配列日。为什么会发生这种情况,我是flot的新手。能不能分享一下你的经验。
var d_register = #{ @total.map{ |t| [t.date.to_time.to_i * 1000 , t.register] } };
// must add 25 000 000 to it for correct position point.
// var d_register = #{ @total.map{ |t| [t.date.to_time.to_i * 1000 + 25000000, t.register] } };
var curr = new Date(#{Date.current.to_time.to_i * 1000}); // get current date
define_flot();
function define_flot(){
var first = new Date(curr.getTime() - curr.getDay() * 24 * 60 * 60 * 1000);
var last = new Date(first.getTime() + 7 * 24 * 60 * 60 * 1000);
$(".week-time").text(
(first.getMonth() + 1) + '/' +
first.getDate() + '/' +
first.getFullYear() + ' - ' +
(last.getMonth() + 1) + '/' +
last.getDate() + '/' +
last.getFullYear() );
var first_day_in_week = first.getTime();
var last_day_in_week = last.getTime();
$.plot("#placeholder", [ d_register ], {
yaxis: {
tickDecimals: 0
},
xaxis: {
mode: "time",
minTickSize: [1, "day"],
min: first_day_in_week,
max: last_day_in_week,
timeformat: "%a"
}
});
}
数据寄存器:
[[1370710800000,1],[1370797200000,7],[1370883600000,1],[1371056400000,0],[1371142800000,0],[1371747600000 1372006800000, 0], [1372093200000, 0], [1372179600000, 0]]
+ 25000000 之后的数据寄存器:
[[1370735800000,1],[1370822200000,7],[1370908600000,1],[1371081400000,0],[1371167800000,0],[13717772600000 1372031800000, 0], [1372118200000, 0], [1372204600000, 0]]