PHP code example of xanpena / svg-chart-builder

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

    

xanpena / svg-chart-builder example snippets


use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
    'dataColor' => 'white',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_BAR, $data, $options);
$svg = $chartBuilder->create();
echo $svg;

use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
    'dataColor' => 'white',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_HORIZONTALBAR, $data, $options);
$svg = $chartBuilder->create();
echo $svg;

use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'labelsColor' => 'white'
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_DOUGHNUT, $data, $options);
$svg = $chartBuilder->create();
echo $svg;

use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    16,
    18,
    40,
    // ... other data ...
];

$options = [
    'labels' => [
        'math',
        'literature',
        'english',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'labelsColor' => 'white'
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_PIE, $data, $options);
$svg = $chartBuilder->create();
echo $svg;

use Xanpena\SVGChartBuilder\SVGChartBuilder;

$data = [
    'math' => [
        11,
        17,
        15,
        // ... other data ...
    ],
    'literature' => [
        21,
        21,
        23,
        // ... other data ...
    ],
    'english' => [
        14,
        9,
        18,
        // ... other data ...
    ]
    // ... other data ...
];

$options = [
    'labels' => [
        '2020/2021',
        '2021/2022',
        '2023/2024',
        // ... other data ...
    ],
    'colors' => [
        '#CDDC39',
        '#00BCD4',
        '#9E9E9E',
        // ... other data ...
    ],
    'axisColors' => [
        'x' => 'red',
        'y' => 'blue'
    ],
    'labelsColor' => 'orange',
];

$chartBuilder = new SVGChartBuilder(SVGChartBuilder::CHART_TYPE_LINE, $data, $options);
$svg = $chartBuilder->create();
echo $svg;