KoolReport's Forum

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

Donut chart formatValue doesn't work #1409

Open Hayriye opened this topic on on Apr 27, 2020 - 5 comments

Hayriye commented on Apr 27, 2020

I'm trying to this,

        DonutChart::create(array(
            "dataSource" => $this->dataStore($this->reportName),
            "columns" => array(
                "CLASS",
                "SECOND" => array(
                    'formatValue' => function ($value) {
                        return $value/3600;
                    },
                    "label" => "Avarage time",
                    "type" => "number",
                ),
            ),
            "colorScheme" => array(
                "#fcb33b",
                "#87b25c",
                "#48a5a9"
            )
        ));

it doesn't work. I want to casting second to hour-min format.Like this 5 hour 30 minute 25 second. FormatValue doesn't work. Anyone help me ?

KoolReport commented on Apr 27, 2020

May I know the result on the DonutChart. Does it show any value?

Hayriye commented on Apr 27, 2020

İt shows query result

KoolReport commented on Apr 27, 2020

We have just perform a test and it seems working well, here is the code:

<?php
    use \koolreport\chartjs\DonutChart;
    $category_amount = array(
        array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
        array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
        array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
        array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
        array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000),
    );

?>

<html>
    <head>
        <title>Test formatValue of DonutChart</title>
    </head>
    <body>
        <h1>Test formatValue of DonutChart</h1>
        <?php
        DonutChart::create(array(
            "title"=>"Sale Of Category",
            "dataSource"=>$category_amount,
            "columns"=>array(
                "category",
                "cost"=>array(
                    "type"=>"number",
                    "label" => "Avarage time",
                    'formatValue'=>function($value) {
                        return $value/2;
                    }
                )
            )
        ));
        ?>
    </body>
</html>
Hayriye commented on Apr 28, 2020

Yes I tried this. This is working. But it is not working in my report. I am using group column for average,

output same for two view

KoolReport commented on Apr 28, 2020

Hi,

It seems to me that your code is not following normal data piping. The piping after report runs will not affect data. If you want to process data from a datastore, you need to use the process() method. Here is the documentation.

I am not sure yet if this affect the formatValue, it should not. Could you please tell me if there is any different if you add the "formatValue" vs not adding it ( in term of displaying result).

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
help needed

None