如何使用PHP在Highcharts柱形图中显示日期和日期

问题描述 投票:0回答:1

我正在尝试使用PHP在Highcharts库仑图中显示日期和日期。我想以(星期四26/12/2019)格式打印日期和日期。现在,它仅显示Day名称,而我正在使用JSON传递Day名称。我尝试解决此问题,但无法解决此问题。

$rate_names = [];
$dates = [];
$day_names = [];
$stars_data = [];

$from_date2 = $from_date;
while (strtotime($from_date2) <= strtotime($to_date)) {

    $day_names[] = date('l', strtotime($from_date2));
    $dates[] = $from_date2;
    $from_date2 = date('Y-m-d', strtotime('+1 day', strtotime($from_date2)));
}


Highcharts.chart('column', {
        chart: {
            type: 'column'
        },
        xAxis: {
            categories: <?= json_encode($day_names) ?>,
            crosshair: true
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Count'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} </b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        series: JSON.parse('<?= $processed_stars_data ?>')
    });
php json highcharts
1个回答
0
投票

要更改高图上xAxis的格式,您可以这样做:

this documention起,您可以混合使用以下内容。

%a: Short weekday, like 'Mon'
%A: Long weekday, like 'Monday'
%d: Two digit day of the month, 01 to 31
%e: Day of the month, 1 through 31
%w: Day of the week, 0 through 6
%b: Short month, like 'Jan'
%B: Long month, like 'January'
%m: Two digit month number, 01 through 12
%y: Two digits year, like 09 for 2009
%Y: Four digits year, like 2009
%H: Two digits hours in 24h format, 00 through 23
%k: Hours in 24h format, 0 through 23
%I: Two digits hours in 12h format, 00 through 11
%l: Hours in 12h format, 1 through 12
%M: Two digits minutes, 00 through 59
%p: Upper case AM or PM
%P: Lower case AM or PM
%S: Two digits seconds, 00 through 59
%L: Milliseconds (naming from Ruby)

从此列表中,%A %d/%m/%y返回的时间类似于Thursday 26/12/2019

因此只需添加或更新您的xAxis

 xAxis: {
            type: 'datetime',
            labels: {
                 formatter: function() {
                     return Highcharts.dateFormat('%A %d/%m/%y', this.value);
                 }
            }
        },
© www.soinside.com 2019 - 2024. All rights reserved.