PHP code example of derafu / chart

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

    

derafu / chart example snippets


use Derafu\Chart\ChartFactory;
use Derafu\Chart\Enum\ChartType;

$chart = (new ChartFactory())->renderFromArray([
    'type' => ChartType::BAR,
    'title' => 'Ventas',
    'label_x' => 'Mes',
    'label_y' => 'Ventas',
    'datasets' => [
        [
            'points' => [
                'Enero' => 10000,
                'Febrero' => 12000,
                'Marzo' => 1200,
                'Abril' => 1350,
                'Mayo' => 5000,
                'Junio' => 5000,
                'Julio' => 5000,
                'Agosto' => 5000,
                'Septiembre' => 15000,
            ],
        ],
    ],
]);

file_put_contents('chart.png', $chart);

use Derafu\Chart\Chart;
use Derafu\Chart\Dataset;
use Derafu\Chart\Enum\ChartType;

$chart = (new Chart(ChartType::BAR))
    ->setTitle('Ventas')
    ->setLabelX('Mes')
    ->setLabelY('Ventas')
    ->addDataset(
        (new Dataset())
            ->setLabel('2024')
            ->setColor('blue')
            ->addPoints([
                'Enero' => 10000,
                'Febrero' => 12000,
                'Marzo' => 1200,
                'Abril' => 1350,
                'Mayo' => 5000,
                'Junio' => 5000,
                'Julio' => 5000,
                'Agosto' => 5000,
                'Septiembre' => 15000,
            ])
    );

file_put_contents('chart.png', $chart->render());