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

Note: Those above properties follows this code rules.

Traits #

Google Charts has been provided with following traits:

  1. TAppLink: Able to refer to application with app() method
  2. TDashboadLink: Able to refer to parent dashboard with dashboard() method
  3. TEnabledPermit: Use enabled() and enabledWhen() to set permission
  4. TParams: Able to get/set parameters with params() method
  5. TWidgetState: Able to get/set persisted state for widget
  6. TParamsPersisted: Able to make params set to widget persisted
  7. TDataSource: Able to receive datasource via dataSource() method
  8. TDetailAction: Able to open detail modal
  9. TExportable: Able to export widget to different formats

Examples #

Create chart from dashboard

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

class StockBoard extends Dashboard
{
    protected function content()
    {
        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.