KoolReport's Forum

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

Google Gauge label value rounding #1991

Closed James Caws opened this topic on on Mar 24, 2021 - 1 comments

James Caws commented on Mar 24, 2021

I've recently upgraded to KoolReport version 5.0.1 from version 4. In v4 I was able to specify a separate value for the needle and a separate value for the displayed reading for my Google Chart Gauges...

Gauge::create( array(
        "dataSource" => array (
                array ( 'label' => 'Avg. Rating', 'value' => array ('v' => 2.56789, 'f' => "2.5" ) )
        ),
        'width' => '200px',
        'height' => '200px',
        "options" => array(
                ...]
        )
));

Since upgrade, Gauges broke. I inspected page source, experimented and found that to get Gauges to show I can only provide one value and KoolReport does rounding of value to generate the displayed reading value:

Gauge::create( array(
        "dataSource" => array (
                array ( 'label' => 'Avg. Rating', 'value' => 2.56789 )
        ),
        'width' => '200px',
        'height' => '200px',
        "options" => array(
                ...
        )
));

Unfortunately this means my displayed value can be misleading. This is a problem when showing small values, e.g. a specific value of 2.56789 is more appropriately shown on the display as 2.5.... rounding to 3 is misleading and doesn't make sense when the needle is nowhere near 2.5.

Has something changed in KoolReport or Google Charts? Can anything be done to achieve what I used to have?

James Caws commented on Mar 25, 2021

I've managed to solve the issue myself by introducing the use of the formatValue feature.

Gauge::create( array(
        'dataSource' => array (
                array ( 'label' => 'Avg. Rating', 'value' => $myFloatValue )
        ),
        'columns' => array (
                'label',
                'value' => array (
                        'formatValue' => function($value) {
                                return sprintf('%.2f', $value);
                        }
                )
        ),
        'width' => '200px',
        'height' => '200px',
        'options' => array (
                ...
        )
));

I see this was added to KoolReport GoogleChart in version 2.75.0, so no idea why it worked in version 4 and then stopped in version 5. Anyway, happy it's now working.

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
solved

None