KoolReport's Forum

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

ChartJS - BarChart - does not show prefix and suffix for columns data #1787

Open MarkoS opened this topic on on Dec 23, 2020 - 2 comments

MarkoS commented on Dec 23, 2020

Hi all,

I am using BarChart to create chart with three columns, where two columns are currency and I have to add suffix to them but it does not work.

use \koolreport\chartjs\BarChart;

Here is my code:

BarChart::create(array(
            "dataStore"=>$this->dataStore("tst_promet_godina"),
            "colorScheme"=>array(
                "#108dc7",
                "#DD1B1B",
                "#525f66"
            ),
            "stacked"=>false,
            "columns"=>array(
                "Datum",
                "Kolicina"=>array(
                    "label"=>"Količina 2020 (kom)",
                    "type"=>"number",
                    "prefix"=>" kom"
                ),
                "Promet"=>array(
                    "label"=>"Promet 2020 (KM)",
                    "type"=>"number",
                    "suffix"=>" KM",
                    "decimals"=>2,
                    "decPoint"=>".",
                    "thousandSep"=>","
                ),
                "PrometStari"=>array(
                    "label"=>"Promet 2019 (KM)",
                    "type"=>"number", 
                    "suffix"=>" KM",
                        "decimals"=>2,
                        "decPoint"=>".",
                        "thousandSep"=>","
                        
                )
            )
        ));

It does not even separate thousand values. I have followed this two examples and configuration: https://www.koolreport.com/examples/reports/chartjs/bar_chart/ https://www.koolreport.com/docs/chartjs/bar_chart/#settings-chartjs-config-for-column

KoolReport commented on Dec 24, 2020

That's strange that we test on our example https://www.koolreport.com/examples/reports/chartjs/bar_chart/, it works for those settings. "suffix", "thousandSep" and "decPoint". Could you please try to test on our example to see how.

MarkoS commented on Dec 24, 2020

Yeah it is strange. I have placed code from example (complete with array data) just below my graph and it shows prefix and suffix as you said. Example works,.. Settings for my code are same. the only thing I could think of is that "number" is different format and it does not work with it well.

Thank I changed example code array (prices) as below:

$category_amount = array(
        array("category"=>"Books","sale"=>32000.33,"cost"=>20000.33,"profit"=>12000.54),
        array("category"=>"Accessories","sale"=>43000.55,"cost"=>36000.32,"profit"=>7000.98),
        array("category"=>"Phones","sale"=>54000.43,"cost"=>39000.26,"profit"=>15000.78),
        array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
        array("category"=>"Others","sale"=>12000.25,"cost"=>6000.35,"profit"=>6000.43),
        );

As you can see I set price numbers 32000.33 and attached image shows decimal places in proper way, separating thousand with ",". In another hand, my graph does not do that, even if price is 1923943.33 for example, with same settings for decimal places etc. What I have noticed, your example graph default price is without thousand separator configuration and IT DOES separate it automatically, without need to configure it.

My SQL query does this to a price number:

ROUND(SUM(Iznos), 2) as Promet

And I am using JOIN to get data together:

$join = new Join($prvi,$drugi,array("Datum"=>"Datum")); 
$join->pipe($this->dataStore("tst_promet_godina")); 

Would JOIN cause this problem?

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