Skip to main content
Topic: Chart Random Color not Working (Read 1366 times) previous topic - next topic

Chart Random Color not Working

Dear @wilvin,

Serious problem regarding chart random colors. I´ve read other posts and didn´t find a solution. Please, help me because charts are crucial to my application.

The forum is not allowing to add files.

Thanks!

Euder


Re: Chart Random Color not Working

Reply #2
You can achieve that by using custom code and adding field color to your table.
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

Re: Chart Random Color not Working

Reply #3
@willvin we are already 4 months with this problem, there is no way to work with a color chart.

There is no way to release it to graphic users in this situation.

We need a solution, they managed to build a fantastic tool that is phprad, plus the bugs make you lose confidence.


Re: Chart Random Color not Working

Reply #5
You can achieve that by using custom code and adding field color to your table.
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
Sorry to be late, but now I badly need colors in charts.
Where have I to put the second block code ("you have to supply the code...")?
TIA
tony

Re: Chart Random Color not Working

Reply #6
There is no way to release it to graphic users in this situation.
We need a solution, they managed to build a fantastic tool that is phprad, plus the bugs make you lose confidence.

Problem is that developers abandoned this tool. They replaced it with fresh new tool -  Radsystems studio -  that have new set of bugs and .... that cost much more than PHPRad.   Sad but true.

Fun fact is that I bought 1 year of support for PHPRad, but at that time developers already knows that this tool will be deprecated soon, and they did not released any new version of the PHPRad, even when users (including me) posted there bug in code with fix too.