PHP code example of aldeebhasan / fast-bi

1. Go to this page and download the library: Download aldeebhasan/fast-bi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aldeebhasan / fast-bi example snippets


use Aldeebhasan\FastBi\Manager\Dimensions;
Dimensions::string('dimension-1',[1,2,4])->build();
Dimensions::number('dimension-2',[1,2,4])->build();
Dimensions::dateTime('dimension-3',['2023-5-5', '2024-6-6'])->build();

// to retrieve the dimension data you can use the `getData()` function.
$dimension = Dimensions::string('dimension-1',[1,2,4])->build();
print($dimension->getData())
//result = ["1","2","4"]//

$dimension = Dimensions::dateTime('dimension',['2023-5-5', '2024-6-6'])->format('Y-m')->build();
print($dimension->getData())
//result = ["2023-5","2024-6"]//

$dimension = Dimensions::raw('dimension', [1, 2, 3, 4])
            ->setTransformer(fn ($x) => $x - 1)
            ->build();
print($dimension->getData())
//result = [0, 1, 2, 3]//

use Aldeebhasan\FastBi\Manager\Metrics;
Metrics::sum('metric-1',[1,2,3])->build();
Metrics::max('metric-2',[1,2,3])->build();
Metrics::min('metric-3',[1,2,3])->build();
Metrics::median('metric-4',[1,2,3])->build();
Metrics::avg('metric-5',[1,2,3])->build();

// to retrieve the metric data you can use the `getData()` function.
$metric = Metrics::sum('metric-1',[1,2,3])->build();
print($metric->getData())
//result = 6//

$metric = Metrics::raw('name', [1, 2, 3])
->setMeasure(fn ($data) => count($data))
->build();
print($metric->getData())
//result = 3//

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::table('users')
        ->labels(['ID', 'Name', 'mobile'])
        ->dimensions([
            Dimensions::number('ids',[1,2,3]),
            'names'=>['Ali', 'Hasan', 'Mohammad'],
            'mobile'=>Dimensions::string('mob',["+01252**","+01252**","+01252**"]),
        ])->render()
//with metrics
Widgets::table('users')
        ->labels(['ID', 'Name', 'mobile'])
        ->dimensions([
            Dimensions::number('ids',[1,2,3]),
            'names'=>['Ali', 'Hasan', 'Mohammad'],
            'mobile'=>Dimensions::string('mob',["+01252**","+01252**","+01252**"]),
        ])->metrics([
            Metrics::count('total',[1,2,4]),
            'average'=>Metrics::avg('avg',[1,2,4])
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::barChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->metrics([
            Metrics::sum('total',[100,200,300]),
            'max-income'=>Metrics::max('avg',[100,200,300]),
            'min-income'=>Metrics::min('avg',[100,200,300])
        ])->render()
        
//To make the bar chart horizontal, you can just add the following settings to the widget:
Widgets::barChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->settings(['direction'=>'y'])   //// make the y axis as the base
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->metrics([
            Metrics::sum('total',[100,200,300]),
            'max-income'=>Metrics::max('avg',[100,200,300]),
            'min-income'=>Metrics::min('avg',[100,200,300])
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::lineChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->render()

//with metrics
Widgets::lineChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->metrics([
            Metrics::sum('total',[100,200,300]),
            'max-income'=>Metrics::max('avg',[100,200,300]),
            'min-income'=>Metrics::min('avg',[100,200,300])
        ])->render()


use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::pieChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->render()

 Widgets::pieChart('profits of pos')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::doughnutChart('profits')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
            'store-invoices'=>[150,110,250],
            Dimensions::number('extra',[10,20,30]),
        ])->render()

 Widgets::doughnutChart('profits of pos')
        ->labels(['2016', '2017', '2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,200,300]),
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

Widgets::scatterChart('profits')
        ->labels(['POS To Store','POS to Extra'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,110,120,130,140,160,200,250]),
            Dimensions::number('store-invoices',[100,200,300,210,300,400,450,600]),
            Dimensions::number('extra',[10,20,30,80,90,150,200,250]),
        ])->render()

Widgets::bubbleChart('bubbles profits')
        ->labels(['POS To Store','POS to Extra'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,110,120,130,140,160,200,250]),
            Dimensions::number('store-invoices',[100,200,300,210,300,400,450,600]),
            Dimensions::number('extra',[10,20,30,80,90,150,200,250]),
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};
//single dimension
Widgets::polarAreaChart('polar profits')
        ->labels(['2016 ','2017','2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[100,110,120]),
        ])->render()
//multi dimensions
Widgets::polarAreaChart('polar profits (multi)')
         ->labels(['2016 ','2017','2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[125,110,120]),
            Dimensions::number('store-invoices',[100,150,175]),
            Dimensions::number('extra',[150,110,150]),
        ])->render()


use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

//single dimension
 Widgets::radarChart('radar profits')
         ->labels(['2016 ','2017','2018','2019',2020])
        ->dimensions([
            Dimensions::number('pos-invoices',[125,150,180,190,200]),
        ])->render()
//multi dimensions
Widgets::radarChart('radar profits (multi)')
         ->labels(['2016 ','2017','2018'])
        ->dimensions([
            Dimensions::number('pos-invoices',[125,110,120]),
            Dimensions::number('store-invoices',[100,150,175]),
            Dimensions::number('extra',[150,110,150]),
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

//single dimension
 Widgets::number('expenses')
        ->labels(['Maintenance Expenses'])
        ->dimensions([
            Dimensions::number('maintainance',[250]),
        ])->render()
//multi dimensions
Widgets::number('incomes')
        ->dimensions([
             Dimensions::number('orders',[100000]),
             Dimensions::number('marketing',[1500]),
            'social-media' => 6000
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

//single dimension
 Widgets::progressBar('expenses')
        ->labels(['Maintenance Expenses'])
        ->dimensions([
            Dimensions::number('maintainance',[250]),
        ])->render()
//multi dimensions
Widgets::progressBar('incomes')
        ->dimensions([
             Dimensions::number('orders',[100000]),
             Dimensions::number('marketing',[1500]),
            'social-media' => 6000
        ])->render()

use Aldeebhasan\FastBi\Manager\{Metrics,Dimensions,Widgets};

//single dimension
 Widgets::geoMap('map')
        ->countries(['US','CA','FR','CN'])
        ->dimensions([
            Dimensions::number('population',['150','200','300','400']),
            'area'=>['1500','2000','3000','6000'],
        ])->render()
//custom names
 Widgets::geoMap('map')
        ->countries(['US','CA','FR','CN'])
         ->labels(['Population','Square Area'])
        ->dimensions([
            Dimensions::number('population',['150','200','300','400']),
            'area'=>['1500','2000','3000','6000'],
        ])->render()