我正在尝试使用flot获取m/d/y格式的时间戳,以便在x轴上显示。我已经通读了API docs,但是时间戳仍然不能转换。我哪里错了?

<!-- Flot demo info -->
<script>
$(document).ready(function() {
//random data
var d1 = [
[(new Date(2016, 6, 23)).getTime(), 55],
[(new Date(2016, 6, 24)).getTime(), 45],
[(new Date(2016, 6, 25)).getTime(), 55],
[(new Date(2016, 6, 26)).getTime(), 65],
[(new Date(2016, 6, 27)).getTime(), 25],
[(new Date(2016, 6, 28)).getTime(), 85],
[(new Date(2016, 6, 29)).getTime(), 15],
];
//flot options
var options = {
series: {
curvedLines: {
apply: true,
active: true,
monotonicFit: true
}
},
colors: ["#26B99A"],
grid: {
borderWidth: {
top: 0,
right: 0,
bottom: 1,
left: 1
},
borderColor: {
bottom: "#7F8790",
left: "#7F8790"
}
}
};
var plot = $.plot($("#security_activity"), [{
label: "Security",
data: d1,
yaxis: {},
xaxis: {
mode: "time",
timeformat: "%m/%d/%y"
},
lines: {
fillColor: "rgba(150, 202, 89, 0.12)"
}, //#96CA59 rgba(150, 202, 89, 0.42)
points: {
fillColor: "#fff"
}
}], options);
});
</script>发布于 2016-06-22 04:36:36
呃,愚蠢的我..。将x轴/y轴选项放在错误的位置。
更新的代码:
<!-- Flot demo info -->
<script>
$(document).ready(function() {
//random data
var d1 = [
[(new Date(2016, 6, 23)).getTime(), 55],
[(new Date(2016, 6, 24)).getTime(), 45],
[(new Date(2016, 6, 25)).getTime(), 55],
[(new Date(2016, 6, 26)).getTime(), 65],
[(new Date(2016, 6, 27)).getTime(), 25],
[(new Date(2016, 6, 28)).getTime(), 85],
[(new Date(2016, 6, 29)).getTime(), 15]
];
//flot options
var options = {
series: {
curvedLines: {
apply: true,
active: true,
monotonicFit: true
}
},
colors: ["#26B99A"],
grid: {
borderWidth: {
top: 0,
right: 0,
bottom: 1,
left: 1
},
borderColor: {
bottom: "#7F8790",
left: "#7F8790"
}
},
yaxis: {},
xaxis: {
mode: "time",
timeformat: "%m/%d/%y",
minTickSize: [1, "day"]
}
};
var plot = $.plot($("#security_activity"), [{
label: "Security",
data: d1,
lines: {
fillColor: "rgba(150, 202, 89, 0.12)"
}, //#96CA59 rgba(150, 202, 89, 0.42)
points: {
fillColor: "#fff"
}
}], options);
});
</script>https://stackoverflow.com/questions/37953960
复制相似问题