[英]Highcharts label format with tickPositioner in a datetime x Axis
In my chart ,I try to display only 5 ticks in a datetime axis, I use the tickPositioner function and set only 5 ticks ,this work perfect but the data labels loss it's format and show only numbers.在我的图表中,我尝试在日期时间轴上只显示 5 个刻度,我使用了 tickPositioner 函数并只设置了 5 个刻度,这个工作完美但数据标签丢失了它的格式并且只显示数字。
I use the formatter function but i need a grouping labels for the zoom.我使用格式化程序功能,但我需要一个用于缩放的分组标签。
It's little hacky, but you need also calculate information about labels and add them, for example: http://jsfiddle.net/AVhaL/这有点hacky,但您还需要计算有关标签的信息并添加它们,例如: http : //jsfiddle.net/AVhaL/
tickPositioner: function (min, max) {
var ticks = this.getLinearTickPositions(this.tickInterval, min, max),
tLen = ticks.length;
ticks.info = {
unitName: "week",
higherRanks: {},
totalRange: ticks[tLen - 1] - ticks[0]
};
return ticks;
}
So according to totalRange
, you need to pass unitName
- it's information which format should be taken from dateTimeLabelFormats .因此,根据totalRange
,您需要传递unitName
- 它是应从dateTimeLabelFormats获取哪种格式的信息。
You only need format label, after put ticks.打勾后,您只需要格式标签。
Options.xAxis.tickPositioner = function () {
const ticks = this.series[0].xData;
let result = [];
for (let index = 0; index < ticks.length; index++) {
result.push(ticks[index]);
}
return result;
};
and format xAxis并格式化 xAxis
labels: {
format: "{value:%b-%Y}",
align: "center"
}
to tooltips到工具提示
tooltip: {
valueSuffix: "",
valuePrefix: "",
xDateFormat: "%B - %Y",
valueDecimals: 0
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.