【问题标题】:yii highcharts how to set date format in x-axisyii highcharts 如何在 x 轴上设置日期格式
【发布时间】: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


【解决方案1】:

正如我已经说过的,你必须为你的系列使用时间戳:

$date_from = (strtotime($data->StartDATE) - 2*86400)*1000;
$date_to = (strtotime($data->ProjectEndDate) + 2*86400)*1000;

$series['series'][] = array(
    "name"=> $data->PROJECT,
    "data"=> array(
        array(
            $date_from,
            0
        ),
        array(
            (time() + 2*86400))*1000 ,
            30,
        array( 
            $date_to,
            100 
        )
    )
) ;

对于 javascript,乘以 1000。

【讨论】:

  • 为什么日期是 - 而日期是 +?以及为什么乘以2
  • 我从网上其他地方抓取了那部分。我如何将以下内容作为图表中的一个点包含在此链接上p2p.wrox.com/access/65577-calculate-percentage-date.html
  • @sharif 我认为这是另一个问题。你的问题是关于highcharts中的日期。现在你在问如何使用 Highcharts ?您可能应该多阅读文档并查看一些示例。
【解决方案2】:

Highcharts 需要时间戳作为 x 值才能在 xAxis 上显示日期。所以 od 2013, 06, 09 应该是 1373328000000 (数字)。

【讨论】:

  • 如何将其转换为正确的时间戳。日期最初来自 MySQL
  • 你可以在javascript中使用Date.UTC() / Date.Parse(),或者在php中使用strtotime() php.net/manual/en/function.strtotime.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多