KoolReport's Forum

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

Multiple columns with data coming from sql. #1974

Open Gabriela Matheus opened this topic on on Mar 16, 2021 - 1 comments

Gabriela Matheus commented on Mar 16, 2021

Hi! I want to create a vertical column chart like this example , but I don't know how get the data from result of sql server, without coming from the array with the values ​​(in the example mentioned above). I'm new to Koolreport, so if you can help me, I'll be grateful. I want to replace this:

  $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),
    );

By data from the sql server. In Report.php, do I have to bring in separate selects? Or can I bring both a UNION ALL? Sorry if you can't relate

Thanks for attention.

Sebastian Morales commented on Mar 17, 2021

Gabriela, pls set up our datasource and use a select query to pipe data to a data store like this:

    //MyReport.php
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                'sqlsrv' => ...,
            )
        );
    }
    protected function setup()
    { 
        $this->src("sqlsrv")
        ->query("select category, sale, cost, profit from table1")
        ->pipe($this->dataStore("salesData"));
    }

Then use the data store as data source for your chart in MyReport.view.php

    //MyReport.view.php
    BarChart::create(array(
        "dataSource" => $this->dataStore("salesData"),
        ...

Let us know if there's any error. Rgds,

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