KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Column chart percent #305

Open arthur opened this topic on on Jun 5, 2018 - 2 comments

arthur commented on Jun 5, 2018

I would like to know if it's possible to display, for each bar, the value and the percent of the total. Let says that we have the sells value for each salesman and their contribution to the total sells.

Thanks !

KoolReport commented on Jun 5, 2018

Yes, it is possible. I guess you have known how to calculate the percentage of each sale to the total (using AggregatedColumn and CalculatedColumn combined) so let say you have had 3 columns: person, sale_amount and sale_percentage, in order to display both values in the chart, you need use the formatValue settings:

ColumnChart::create(array(
    "columns"=>array(
        "person",
        "sale_amount"=>array(
            ...
            "formatValue"=>function($value,$row)
            {
                return '$'.$row["sale_amount"].' - '.$row["sale_percent"].'%';
            }
        )
    )
))

Hope that helps.

arthur commented on Jun 5, 2018

Perfect !

And last question : When I add an extra bar on the view file like this below, the value display well, but the percent display INF. Do you know why ?

$sum_row = array(
    "Ccial"=>"Napsis",
    "PO"=>$this->dataStore("PO_marge")->sum("PO")
);

$data = $this->dataStore("PO_marge")->data(); // <-- get data from store
array_push($data,$sum_row);
$this->dataStore("PO_marge")->data($data); //<--Push back data to store

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None