当前位置 : 主页 > 手机开发 > 其它 >

graph – 单一类别中单个条形的高图改变颜色

来源:互联网 收集:自由互联 发布时间:2021-06-22
我有一个列范围图,想要定义单个条线的颜色.如果你看到图片中的第二组.根据某种情况,我会把它改成不同的颜色. $schedule [] = array($date_from,(date(‘Ym-d’,strtotime($model [‘ProjectEndDate’]))
我有一个列范围图,想要定义单个条线的颜色.如果你看到图片中的第二组.根据某种情况,我会把它改成不同的颜色. $schedule [] = array($date_from,(date(‘Ym-d’,strtotime($model [‘ProjectEndDate’]))> date(‘Ym -d’))?$today * 1000:$date_to) ;如果endate不大于今天,则将颜色更改为红色.

我该怎么做?

在视野中

$('#container').highcharts({
    'chart':{
        'type':'columnrange',
        'inverted':true,
            },
    'exporting':{
        'enabled':true
        },

    'title':{
        'text':'Projects incomplete in 2013'
        },
    'xAxis':{
        'categories':<?=$cat?>
        },
    'yAxis':{
        'title':'Date',
        'type':'datetime',
        'dateTimeLabelFormats':{                
            'month':'%b'
        },
        'min':Date.UTC(2013,00,01)
    },

    'tooltip':{
        formatter: function(){  
                return '<b>' +this.series.name + ':</b> '+ Highcharts.dateFormat('%e %b, %Y', this.point.low) + ' - ' +  Highcharts.dateFormat('%e %b, %Y', this.point.high) +'<br/>' ;
              }  
        },
    'legend':{
        'enabled':false
        },
    'series':[
                {
                    'name':'Start - End',
                    'data':<?=$data?>
                    },
                    {
                    'name':'Forecast',
                    'data':<?=$schedule?>,
                    'color': 'green'    
                    },
                    {
                    'name':'Actual',
                    'data':<?=$complete?>,
                    'color': 'yellow'   
                    }
                ]

});

在我的控制器中我有

public function actionGraph(){      

        $command = Yii::app()->db->createCommand("
                SELECT
                    view_webprojectreport.PROJECT,
                    view_webprojectreport.StartDATE,
                    view_webprojectreport.ProjectEndDate,
                    view_webprojectreport.PERCENT,
                    view_webprojectreport.ASAAREA
                FROM
                    view_webprojectreport
                WHERE
                view_webprojectreport.StartDATE >= '2013' AND
                view_webprojectreport.ProjectEndDate IS NOT NULL AND
                view_webprojectreport.PERCENT < 100
                ORDER BY
                view_webprojectreport.PERCENT DESC
                ")->queryAll();

        $series = array();
        $cat = array();
        $totalLength = array();
        $schedule = array();
        $complete = array();

        foreach ($command as $key => $model) {
            $cat[] = $model['PROJECT'];
            $date_from = (strtotime($model['StartDATE']) + 1*86400)*1000;
            $date_to = (strtotime($model['ProjectEndDate']) + 1*86400)*1000;            
            $totalLength[] = array($date_from,$date_to);            

            $today = time();
            $startdate = strtotime($model['StartDATE']); 
            $enddate = strtotime($model['ProjectEndDate']); 
            $diff_total = $enddate - $startdate;
            $diff_today = $today - $startdate;
            $percentage_date=round(($diff_today/$diff_total)*100,2);


            $duration = ( ((strtotime($model['ProjectEndDate']) + 1*86400)*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000) );         
            $burn = ((time() )*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000);
            $pBurned = $burn/$duration;
            $time = $time = strtotime( ($date_from + $pBurned) );

            //echo date('Y-m-d') . " : " . date('Y-m-d',strtotime($model['ProjectEndDate'])) . "<br>";
            // place check for calculating if project end date is in past
            $schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to); 




            $percentage_to_get = round((float)$model['PERCENT'],2);
            $percentage_of_days =  ((int)$model['PERCENT'] == 0)? 0 : floor($diff_total/100*$percentage_to_get);
            //echo date('Y-m-d', $startdate) . " : " . date('Y-m-d', $startdate + $percentage_of_days ) . "<br>";
            //echo $startdate . " : " . ($startdate + $percentage_of_days) . "<br>";
            $percentComplete = (($startdate + $percentage_of_days)+ 1*86400)*1000;  

            $complete[] = array($date_from,$percentComplete);

        }


        $series = array("series"=>array(
                array(
                    'name'=>'Start - End',
                    'data'=>$totalLength
                    ),
                array(
                    'name'=>'Forecast',
                    'data'=>$schedule,
                    'color'=> 'green'   
                    ),
                array(
                    'name'=>'Actual',
                    'data'=>$complete,
                    'color'=> 'yellow'  
                    )
                ));

        print_r($series);
        $this->render('graph',array(                
                'cat'=>json_encode($cat),
                "data"=>json_encode($totalLength),
                "schedule"=>json_encode($schedule),
                "complete"=>json_encode($complete),
                "series"=>json_encode($series)
        ));
    }

时间表输出

[[1357689600000,1372064004000],[1360972800000,1.3686588e+12],[1359158400000,1372064004000],[1.3630464e+12,1365721200000],[1359417600000,1372064004000],[1.3709916e+12,1372064004000],[1.3686588e+12,1372064004000],[1.3681404e+12,1372064004000],[1.3699548e+12,1372064004000],[1366930800000,1372064004000]]

我如何在这里加入颜色?

$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);

我找到了http://jsfiddle.net/Q2JMF/2/并尝试实施但没有工作.图表什么都没显示

我在jsfiddle http://jsfiddle.net/shorif2000/z4HXX/2/上的例子

你的观点应该是对象:

{
   y:10,
   color: 'red'
}

所以数据看起来像:

data:[{
   y:10,
   color: 'red'
},4,5,6,7,7]

如何准备正确的结构:

http://php.net/manual/en/function.json-encode.php

网友评论