簡體   English   中英

如何在highcharts中格式化x軸標簽

[英]How do I format x-axis label in highcharts

我有以下高清輸出: 在此輸入圖像描述

我只想在x軸標簽上看到2月10日而不是2月10日18:00。 因此,所有xaxis標簽都將像2月10日,2月12日,依此類推。 但工具提示將與輸出屏幕相同。 我如何格式化xaxis以便我將獲得2月10日,2月12日等等,而不是2月10日18:00,2:00-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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM