转换高图表中的日期格式

convert date format in highcharts

本文关键字:日期 格式 高图表 转换      更新时间:2023-09-26

嗨,我在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轴上,但我想更改这样的日期格式:

10月31日至11月4日11月12日11月3日类似这种格式的

我怎么能做到这一点如果有人能帮我,请帮我,我无法得到解决方案。

提前感谢

使用格式化程序方法: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>

您可以进行

"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"]
         };

http://api.highcharts.com/highcharts#Highcharts.dateFormat