Highchart single bar color change in one category

I have a column column and you want to determine the color of one row of a row. If you see the second set in the picture. depending on some condition, I would have to change this to a different color. $schedule[] = array($date_from, ( date('Ym-d',strtotime($model['ProjectEndDate'])) > date('Ym-d') )? $today*1000 : $date_to); If the endate value is not greater than today, change the color to red.

enter image description here

How can I do it?

in sight

 $('#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' } ] }); 

In my controller I have

 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('Ym-d') . " : " . date('Ym-d',strtotime($model['ProjectEndDate'])) . "<br>"; // place check for calculating if project end date is in past $schedule[] = array($date_from, ( date('Ym-d',strtotime($model['ProjectEndDate'])) > date('Ym-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('Ym-d', $startdate) . " : " . date('Ym-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) )); } 

schedule output

 [[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]] 

How do I incorporate color into this?

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

I found http://jsfiddle.net/Q2JMF/2/ and is trying to implement, but does not work. graph does not display anything

My jsfiddle example is http://jsfiddle.net/shorif2000/z4HXX/2/

+4
source share
1 answer

Your point should be object:

 { y:10, color: 'red' } 

So the data should look like this:

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

How to prepare the correct structure:

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

+7
source

Source: https://habr.com/ru/post/1487508/


All Articles