嗨我在Highchart中有一些类别:
Categories:["2015-10-31", "2015-11-04", "2015-11-12", "2015-11-03", "2015-11-11", "2015-11-02", "2015-11-01", "2015-11-13"]
它在x轴上显示,但我想改变这样的日期格式:
oct 31 nov 4 nov 12 nov 3,nov 11 有点像这种格式
我怎样才能达到这个目的 如果有人可以帮助我,请帮助我无法得到解决方案。
提前致谢
答案 0 :(得分:1)
你可以做到
"xAxis": {
"type": "datetime",
"labels": {
"format": "{value:%b %d}"
},
categories:["2015-10-31", "2015-11-04", "2015-11-12", "2015-11-03", "2015-11-11", "2015-11-02", "2015-11-01", "2015-11-13"]
};
答案 1 :(得分:1)
使用格式化程序方法:http://api.highcharts.com/highcharts#xAxis.labels.formatter
示例:
$(function () {
var months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
];
$('#container').highcharts({
title: {
text: 'Example'
},
xAxis: {
categories: ["2015-10-31", "2015-11-04", "2015-11-12"],
labels: {
formatter: function () {
var date = new Date(this.value);
return months[date.getMonth()] + ' ' + date.getDate();
}
}
},
series: [{
data: [1, 2, 3]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 500px"></div>