ConsoleTVs / Charts

[Deprecated] Charts for Laravel
MIT License
77 stars 34 forks source link

[QUESTION] Tooltip valueFormatter #18

Open WIDESRL opened 1 year ago

WIDESRL commented 1 year ago

Using Echarts as chart library and trying to format the tooltips. Starting from a set of options like:

$chart->options([
    'tooltip' => [
        'formatter' => '{b0}: {c0}<br />{b1}: {c1}',
    ]
]);

It works perfectly and 'formatter' allows to choose what will be printed in the tooltip. The matter is I would also like to use the valueFormatter (https://echarts.apache.org/en/option.html#tooltip.valueFormatter) callback to format a number into a currency string, so tried:

$chart->options([
    'tooltip' => [
        'formatter' => '{b0}: {c0}<br />{b1}: {c1}',
        'valueFormatter' => function($value){
            return number_format($value, 2, ',', '.');
        }
    ]
]);

The chart is still working but an error in console is fired on every mouseover on a value bar and no tooltips are showing anymore.

Anyone came to a solution for something similar? TYVM