此图表(行)完美运行。但是我对dateFormat()有格式问题:我无法以Y-m-d H-M-S格式显示时间。
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="chart"></div>
<script>
$(document).ready(function() {
$("#chart").highcharts({
xAxis: {
type: "datetime",
labels: {
formatter: function() {
return Highcharts.dateFormat("%I:%M", this.value);
},
}
},
yAxis: [{
labels: {
formatter: function() { return (this.value) },
}
}],
tooltip: {
formatter: function() {
var s = "<span>" + Highcharts.dateFormat("%Y-%m-%d %H:%M", this.x) + "</span>";
s += "<table>",
$.each(this.points, function(i, point) {
s += '<tr><td><span>' + point.series.name + "</span> :</td><td></strong>" + point.y + "</strong></td></tr>";
});
s += "</table>"
return s;
},
shared: true,
style: {
"line-height": "120%"
},
useHTML: true
},
series: [{
name: '1',
data: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
}, {
name: '2',
data: [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
}, {
name: '3',
data: [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]
}],
});
});
</script>
</body>
</html>
为什么工具提示给我1970-01-01 00 什么时候应该给我2016-02-05 02:00 这段代码有什么问题 和xAxis给我00:00:00.0002 ??
答案 0 :(得分:2)
您需要添加xAxis信息,只需添加pointStart(设置起点)和pointInterval(X数据之间的间隔)。
plotOptions: {
series: {
pointStart: Date.UTC(2016, 01, 5,2),
pointInterval: 3600 * 1000 // one Hour
}
},