PHP code example of daikazu / cli-charts

1. Go to this page and download the library: Download daikazu/cli-charts 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/ */

    

daikazu / cli-charts example snippets




use Daikazu\CliCharts\ChartFactory;

$data = [
    'Jan' => 120,
    'Feb' => 180,
    'Mar' => 150,
    'Apr' => 220,
];

$chart = ChartFactory::create('bar', $data, [
    'title' => 'Monthly Sales',
    'width' => 60,
]);

echo $chart->render();

$chart = ChartFactory::create('bar', $data, $options);

$data = [
    'Food'          => 1200,
    'Rent'          => 1800,
    'Transport'     => 400,
    'Entertainment' => 350,
    'Utilities'     => 250,
];

$chart = ChartFactory::create('bar', $data, [
    'title' => 'Monthly Expenses ($)',
    'width' => 60,
]);

echo $chart->render();

$chart = ChartFactory::create('vbar', $data, $options);

$data = [
    'Jan' => 120,
    'Feb' => 180,
    'Mar' => 150,
    'Apr' => 220,
    'May' => 190,
    'Jun' => 250,
];

$chart = ChartFactory::create('vbar', $data, [
    'title' => 'Monthly Sales',
    'width' => 60,
    'height' => 15,
    'showValues' => true,
    'gridLines' => true,
]);

echo $chart->render();

$chart = ChartFactory::create('line', $data, $options);

$data = [
    'Jan' => 120,
    'Feb' => 180,
    'Mar' => 150,
    'Apr' => 220,
    'May' => 190,
    'Jun' => 250,
];

$chart = ChartFactory::create('line', $data, [
    'title' => 'Sales Trend',
    'width' => 60,
    'height' => 15,
    'lineColor' => 'cyan',
    'pointColor' => 'red',
]);

echo $chart->render();

$chart = ChartFactory::create('pie', $data, $options);

$data = [
    'Chrome'  => 65,
    'Safari'  => 19,
    'Firefox' => 8,
    'Edge'    => 5,
    'Other'   => 3,
];

$chart = ChartFactory::create('pie', $data, [
    'title' => 'Browser Market Share',
    'width' => 60,
]);

echo $chart->render();

$chart = ChartFactory::create('stacked', $data, $options);
// Alias: ChartFactory::create('sbar', $data, $options);

$data = [
    'Chrome'  => 65,
    'Safari'  => 19,
    'Firefox' => 8,
    'Edge'    => 5,
    'Other'   => 3,
];

$chart = ChartFactory::create('stacked', $data, [
    'title' => 'Browser Market Share',
    'width' => 60,
]);

echo $chart->render();

$chart = ChartFactory::create('percent', $data, $options);
// Alias: ChartFactory::create('pbar', $data, $options);

$data = [
    'Chrome'  => 65,
    'Safari'  => 19,
    'Firefox' => 8,
    'Edge'    => 5,
    'Other'   => 3,
];

$chart = ChartFactory::create('percent', $data, [
    'title' => 'Browser Market Share',
    'width' => 60,
]);

echo $chart->render();

ChartFactory::create(string $type, array $data, array $options = []): Chart

public function render(): string

use Daikazu\CliCharts\BarChart;
use Daikazu\CliCharts\VerticalBarChart;
use Daikazu\CliCharts\LineChart;
use Daikazu\CliCharts\PieChart;
use Daikazu\CliCharts\StackedBarChart;
use Daikazu\CliCharts\PercentageBarChart;

$chart = new BarChart($data, $options);
echo $chart->render();
bash
php demo.php