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

如何使用PHP在Highcharts柱形图中显示日期,php,json,highcharts,Php,Json,Highcharts,我试图用PHP在Highcharts-Coulmn图中显示日期和日期。我想以(2019年12月26日星期四)格式打印日期和日期。现在它只显示日期名称,我使用JSON传递日期名称。我试图解决这个问题,但我没能解决这个问题 $rate_names = []; $dates = []; $day_names = []; $stars_data = []; $from_date2 = $from_date; while (strtotime($from_date2) <= strtotime($

我试图用PHP在Highcharts-Coulmn图中显示日期和日期。我想以(2019年12月26日星期四)格式打印日期和日期。现在它只显示日期名称,我使用JSON传递日期名称。我试图解决这个问题,但我没能解决这个问题

$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)));
}


$rate_names=[];
$dates=[];
$day_name=[];
$stars_data=[];
$from_date2=$from_date;

(strotime($from_date2)要更改highcharts上的
xAxis
格式,可以执行以下操作:

从你可以使用下面的混合

%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
返回时间,如
2019年12月26日星期四

因此,只需添加或更新您的
xAxis
,如下所示:

 xAxis: {
      type: 'datetime',
      labels: {
           formatter: function() {
                return Highcharts.dateFormat('%A %d/%m/%y', this.value);
           }
      }
 },

对于这种情况,有两种解决方案。 首先-从服务器站点以以下格式设置xAxis.categories数组:

['Thursday 26/12/2019', 'Thursday 27/12/2019', 'Thursday 28/12/2019', ...etc];
演示:

或者从Highcharts站点使用Highcharts格式化程序回调功能获取想要的格式。如下所示:

演示:


API:


API:

您想在海图上的xAxis中显示此格式(
2019年12月26日星期四
)吗?我说得对吗?是的,我想在x轴上显示
['Thursday 26/12/2019', 'Thursday 27/12/2019', 'Thursday 28/12/2019', ...etc];