【发布时间】:2013-06-20 10:01:24
【问题描述】:
我有一个折线图,我试图在 x 轴上设置日期格式,但它改为显示时间。
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'type'=>'spline',
'title' => array('text' => 'Project Report'),
'xAxis' => array(
'type'=> 'datetime',
'dateTimeLabelFormats'=>array( // don't display the dummy year
'month'=> '%e %b',
'year'=> '%y'
),
),
'yAxis' =>array(
'title' => array('text' => 'Percent %'),
'min'=>0,
'max'=>100
),
'series' =>$series['series']
)
));
这样显示如下图
我的系列数组:
$date_from = date("Y, m, d",strtotime($data->StartDATE) - 2*86400);
$date_to = date("Y, m, d",strtotime($data->ProjectEndDate) + 2*86400);
$series['series'][] = array("name"=>$data->PROJECT,"data"=>array(array($date_from,0),array( date("Y, m, d",strtotime( date('Y-m-d') + + 2*86400) ) ,(int) 30),array( $date_to ,100 ))) ;
这个数组的输出是:Array ( [name] => Fastnet OffshWest Shetland [data] => Array ( [0] => Array ( [0] => 2013, 06, 09 [1] => 0 ) [1] => Array ( [0] => 2013, 06, 20 [1] => 30 ) [2] => Array ( [0] => 2013, 12, 13 [1] => 100 ) ) )
我也试过
$date_from = gmdate('d.m.Y H:i', strtotime($data->StartDATE) );
$date_to = gmdate('d.m.Y H:i', strtotime($data->ProjectEndDate));
$series['series'][] = array("name"=>$data->PROJECT,"data"=>array(array($date_from,0),array( gmdate('d.m.Y H:i', strtotime( date('Y-m-d') ) ) ,(int) 30),array( $date_to ,100 ))) ;
也不行
这是我想要的示例,但是我缺少结束日期信息。这是一个甘特图。我还想包括enddate。当前显示来自startdate 的完成百分比。如果可能的话,我还想用另一种颜色显示使用当前日期应该完成多少。
【问题讨论】:
-
尝试使用时间戳
strtotime(在您的$series数组中) -
尝试使用格式化程序
-
@strikers 我将如何实现这一目标?
-
您可以在 xAxis:{labels:{formatter}} 中找到 xAxis 标签的格式化程序。例如api.highcharts.com/highcharts#xAxis.labels.formatter
-
我已经包含了一个甘特图的excel示例
标签: php yii highcharts date-format