KoolReport's Forum

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

Sql server display data on google charts #2012

Open mustafa bulu opened this topic on on Apr 5, 2021 - 1 comments

mustafa bulu commented on Apr 5, 2021

I'm new to koolreport and I want to try google charts. I set up my sql server connection, but I don't know how to get data from the sql server and use it. I want to make a simple table with the Products.ProductName and Products.UnitPrice components using the Northwind database. In the examples section, data is given directly, but I could not find how to extract data from the sql server.

My codes:

index.php

<?php
require_once "../../../../../autoload.php";
require_once "Report.php";

$report = new Report;
$report->run()->render();


Report.view.php

<?php
    use \koolreport\widgets\google\ColumnChart;
    use \koolreport\widgets\google\BarChart;
    use \koolreport\widgets\google\Gauge;
    use \koolreport\widgets\google\Timeline;
    $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),
    );
?>
<html>
    <head>
        <title>Test multiple google charts</title>
    </head>
    <body>
        <h1>Test multiple google charts</h1>
        <p class="lead">
        There was issue that multiple google charts which are different in packages and stability
        loaded in a sample.
        Only the previous charts works but the rest.
        </p>

        <h2>BarChart</h2>
        <?php
        ColumnChart::create(array(
            "title"=>"Sale Report",
            "dataSource"=>$category_amount,
            "columns"=>array(
                "category",
                "sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
                "cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
                "profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
            )
        ));
        ?>

        <h2>BarChart</h2>
        <?php
        BarChart::create(array(
            "title"=>"Sale Report",
            "dataSource"=>$category_amount,
            "columns"=>array(
                "category",
                "sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
                "cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
                "profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
            )
        ));
        ?>


        <h2>Now Gauge Chart</h2>

        


        

    </body>
</html>

Report.php


<?php

class Report extends \koolreport\KoolReport
{
    public function settings()
    {
        $pathh = '\koolreport\datasources\SQLSRVDataSource';
        return array(
            "dataSources"=>array(
                "sqlserver"=>array(
                    "connectionString" => "sqlsrv:Server=tcp:127.0.0.1;Database=NORTHWND",
                    "username" => "sa",
                    "password" => "---"
                    
                   
                ),
            )
        );


        





    }
    

}

Sebastian Morales commented on Apr 6, 2021

Please check our example and documentation for connecting to SQL Server and select its data:

https://www.koolreport.com/examples/reports/datasources/sqlserver_report/

https://www.koolreport.com/docs/datasources/pdodatasource/

https://www.koolreport.com/docs/datasources/sqlsrvdatasource/

If you have any problem, let us know with error messages and screenshots. Tks,

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