【发布时间】:2016-02-18 21:12:07
【问题描述】:
使用 SO 中的各种帖子/问题作为参考,我创建了一个散点图 jsfiddle
xAxis: {
opposite:true,
type: 'datetime',
gridLineWidth: 1,
gridLineDashStyle: 'ShortDot',
gridLineColor:'black',
alternateGridColor: 'lightgrey',
tickInterval: 3 * 30 * 24 * 3600 * 1000, // 1 quarter
labels: {
//align: "left",
//padding:200,
formatter: function () {
var s = "";
if (Highcharts.dateFormat('%b', this.value) == 'Jan') {
s = s + "Q1"
};
if (Highcharts.dateFormat('%b', this.value) == 'Apr') {
s = s + "Q2"
};
if (Highcharts.dateFormat('%b', this.value) == 'Jul') {
s = s + "Q3"
};
if (Highcharts.dateFormat('%b', this.value) == 'Oct') {
s = s + "Q4"
};
s = s + " " + Highcharts.dateFormat('%Y', this.value);
return s;
}
},
plotLines: [{
color: 'red', // Color value
value: now, // Value of where the line will appear
width: 2, // Width of the line
label: {
text: 'Now',
align: 'center',
verticalAlign: 'bottom',
y: +20,
rotation: 0
}
}]
},
但我对 X 轴标签位于刻度线附近感到震惊。 如何移动到网格的中间?
我试过 align, padding 但没有帮助。当时间线增加时,我仍然应该将标签放在中间。 我应该对 tickInterval 做些什么吗?这可能是我缺少的一个简单属性。
我找到了这个链接 jsfiddle,它解决了我的问题,但有 2 个 x 轴,我正在从列表中填充数据。
【问题讨论】:
-
使用类别轴,您可以使用 'tickMarkPlacement:between'。但由于您使用的是日期时间轴,您唯一的选择可能是设置标签的“x”属性,并将它们推到右侧或左侧
标签: javascript jquery highcharts data-visualization axis-labels