KoolReport's Forum

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

MySql data to Stacked BarChart #1258

Open farish opened this topic on on Jan 15, 2020 - 1 comments

farish commented on Jan 15, 2020

Hi, I am new to koolreport. My question, how can I populate a Bar Chart as the example image below. through MySQL?

My PHP Code so far:

    protected function setup()
    {
        $this->src("players-db")
        ->query("SELECT PState, PRole, COUNT(*) as P_Role_Count FROM p_data GROUP BY PState ORDER BY PState asc ") 

        ->pipe($this->dataStore("result"));
    })
    <?php
        \koolreport\widgets\google\ColumnChart::create(array(
            "title"=>"Players Data",
            "dataSource"=>$this->dataStore("result"),
            "columns"=>array(
                "PState"=>array(
                    "label"=>"State",
                    "type"=>"string"
                ),
                "P_Role_Count"=>array(
                    "label"=>"Roles",
                    "type"=>"number"
                )                
            ),
            "options"=>array(
                "isStacked"=>true
            )
        ));
    ?>

My DB:

The Bar Chart generated not as expected

Any helps are appreciated. Thanks!

KoolReport commented on Jan 15, 2020

You need to use the Cube process with "rows"=>"pState" and "columns"=>"pRole". So you will have the 2 dimension table with row is the state and columns are list of pRole. After that you feed data into ColumnChart with isStacked=true, you will get your desired chart.

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