PHP code example of maantje / charts

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

    

maantje / charts example snippets


use Maantje\Charts\Bar\Bar;
use Maantje\Charts\Bar\Bars;
use Maantje\Charts\Chart;

$chart = new Chart(
    series: [
        new Bars(
            bars: [
                new Bar(name: 'Jan', value: 222301),
                new Bar(name: 'Feb', value: 189242),
                new Bar(name: 'Mar', value: 144922),
            ],
        ),
    ],
);

echo $chart->render();

use Maantje\Charts\Chart;
use Maantje\Charts\Line\Line;
use Maantje\Charts\Line\Lines;
use Maantje\Charts\Line\Point;

$chart = new Chart(
    series: [
        new Lines(
            lines: [
                new Line(
                    points: [
                        new Point(x: 0, y: 0),
                        new Point(x: 100, y: 4),
                        new Point(x: 200, y: 12),
                        new Point(x: 300, y: 8),
                    ],
                ),
                new Line(
                    points: [
                        [0, 0],
                        [100, 4],
                        [200, 12],
                        [300, 8],
                    ],
                ),
            ],
        ),
    ],
);

echo $chart->render();

use Maantje\Charts\Boxplot\Boxplot;
use Maantje\Charts\Boxplot\Boxplots;
use Maantje\Charts\Chart;

$chart = new Chart(
    series: [
        new Boxplots(
            boxplots: [
                new Boxplot(name: 'Jan', values: [12, 30, 45, 60, 88]),
                new Boxplot(name: 'Feb', values: [20, 35, 50, 70, 95, 130, 4]),
            ],
        ),
    ],
);

echo $chart->render();

use Maantje\Charts\Bar\Bar;
use Maantje\Charts\Bar\BarLine;
use Maantje\Charts\Bar\Bars;

$bars = new Bars(bars: [
    new Bar(name: 'Jan', value: 42000),
    new Bar(name: 'Feb', value: 51000),
    new Bar(name: 'Mar', value: 47000),
]);

$chart = new Chart(
    series: [
        $bars,
        new BarLine(bars: $bars, values: [45000, null, 50000], color: 'red', pointColor: 'red'),
    ],
);

use Maantje\Charts\Annotations\PointAnnotation;
use Maantje\Charts\YAxis;

$chart = new Chart(
    yAxis: new YAxis(
        annotations: [
            new PointAnnotation(x: 200, y: 120, label: 'Important Point'),
        ],
    ),
    // ...
);