1
Bugs / Re: Chart Random Color not Working
For example you table named status with the ff fields:
id
status
color
then you'll have to make a new file on the controllers folder.
let's name it ChartController with the ff code:
Code: [Select]
<?php
class ChartController extends BaseController{
function StatusChart(){
$db = $this->GetModel();
$arr = array();
$sqltext = "select count(id) as value, status as label, color from status";
$queryparams = null;
$dataset1 = $db->rawQuery($sqltext, $queryparams);
$arr['labels']=array_map(function($var){ return $var['label']; }, $dataset1);
$arr['colors']=array_map(function($var){ return $var['color']; }, $dataset1);
$arr['datasets'][] = array_map(function($var){ return $var['value']; }, $dataset1);
return $arr;
}
}
Then you'll have to supply the code above by
Code: [Select]
//Custom controller created
$cModel= new ChartController();
//Get the value of function status chart
$chartdata = $cModel->StatusChart();
//Supply the return value to the backgroundColor property.
backgroundColor:[
<?php echo json_encode($chartdata['colors']); ?>,
]
P.S. sorry for my english