在highcharts中格式化Xaxis timedate

时间:2016-05-20 11:05:38

标签: jquery css highcharts

如何格式化xAxis timedata,如图所示。 我试过的是:

xAxis: {
        allowDecimals: false,
        type: "datetime",
        categories: [Date.UTC(2013, 0, 7),Date.UTC(2013, 0, 9),Date.UTC(2014, 0, 3),Date.UTC(2015, 0, 5),Date.UTC(2016, 0, 7)],
        labels: {
            //format: '{value: %A, </b> %y </b> %B}',
            formatter: function () {
                var dayStr = Highcharts.dateFormat('%A', this.value);
                var monthstr = Highcharts.dateFormat('%B', this.value);
                var yearstr = Highcharts.dateFormat('%y', this.value);
                var finaldate = '<div>' + dayStr + '</div></br><div>' + yearstr + monthstr + '</div>'
                return finaldate;       // clean, unformatted number for year
            }
        }
    },

预期产量: enter image description here

提前感谢!!

1 个答案:

答案 0 :(得分:1)

我通过添加useHTML

来修复它
useHTML: true,
            //format: '{value: %A, </b> %y </b> %B}',
            formatter: function () {
                var dayStr = Highcharts.dateFormat('%A', this.value);
                var monthstr = Highcharts.dateFormat('%B', this.value);
                var yearstr = Highcharts.dateFormat('%y', this.value);
                var finaldate = '<div>' + dayStr + '</div><div>' + yearstr + ' ' + monthstr + '</div>'
                return finaldate;       // clean, unformatted number for year
            }