gpt4 book ai didi

highcharts - 如何设置 highcharts 中 x 轴标签的格式

转载 作者:行者123 更新时间:2023-12-02 12:27:35 24 4
gpt4 key购买 nike

我有以下 Highcharts 输出:enter image description here

我只想在 x 轴标签中看到 Feb-10,而不是 Feb-10 18:00。因此所有 xaxis 标签都将类似于 Feb-10、Feb-12 等。但工具提示将与输出屏幕相同。如何格式化 xaxis 以便获得 Feb-10、Feb-12 等,而不是 Feb-10 18:00、Feb-12 20:00 等。

$(function () {
$('#container').highcharts({
chart: {
zoomType: 'xy',
spacingRight: 20
},
credits: {
enabled: false
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
labels: {
overflow: 'justify'
},
startOnTick: true,
showFirstLabel: true,
endOnTick: true,
showLastLabel: true,
categories: dateAndTimeArray,
tickInterval: 10,
labels: {
rotation: 0.1,
align: 'left',
step: 10,
enabled: true
},
style: {
fontSize: '8px'
}
},
yAxis: {
title: {
text: 'Measurement value'
}
},
tooltip: {
xDateFormat: '%Y-%m-%d %H:%M',
shared: true
},
legend: {
enabled: false
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
lineWidth: 1,
marker: {
enabled: false
},
shadow: false,
states: {
hover: {
lineWidth: 1
}
},
// threshold: null
}
},
series: [{
type: 'line',
name: 'Value',
data: chartData,
marker: {
enabled: false
}
}]
});
});

最佳答案

酷,试试这个:

将此格式化程序添加到您的 xAxis labels 对象中:

xAxis {
...
labels: {
...
formatter: function() {
return this.value.toString().substring(0, 6);
},
}
}

链接:http://jsfiddle.net/tn6Kw/9/

关于highcharts - 如何设置 highcharts 中 x 轴标签的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21838738/

24 4 0