KWidget

Overview #

KWidget is special widget which is able to wrap any KoolReport Widget so that it will fit into Dashboard environment.

Settings #

Namedescription
useGet/set the class name of KoolReport Widget you want to wrap
settingsGet/set the settings provided to KoolReport Widget
dataSourceGet/set the datasource provide to KoolReport Widget

Examples #

Create chart from dashboard

<?php 
use \koolreport\dashboard\Dashboard;
use \koolreport\dashboard\widgets\KWidget;

class StockBoard extends Dashboard
{
    protected function widgets()
    {
        KWidget::create()
            ->use(\koolreport\chartjs\ColumnChart::class)
            ->settings([
                "isStacked"=>true
            ])
            ->dataSource(
                ShopDB::table("stocks")
                    ->groupBy("product")
                    ->select("product")
                    ->sum("store1")
                    ->sum("store2")
            )
    }
}

Create a separate widget class

<?php
use \koolreport\dashboard\widgets\KWidget;

class MyColumnChart extends KWidget
{
    protected function onInit()
    {
        $this
            ->use(\koolreport\chartjs\ColumnChart::class)
            ->settings([
                "isStacked"=>true
            ]);
    }

    protected function dataSource()
    {
        return ShopDB::table("stocks")
                ->groupBy("product")
                ->select("product")
                ->sum("store1")
                ->sum("store2");
    }
}

Get started with KoolReport

KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.