PHP code example of macocci7 / php-boxplot
1. Go to this page and download the library: Download macocci7/php-boxplot 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/ */
macocci7 / php-boxplot example snippets
ci7\PhpBoxplot\Boxplot;
$data = [
'1st' => [ 75, 82, 96, 43, 78, 91, 84, 87, 93, ],
'2nd' => [ 66, 74, 62, 100, 72, 68, 59, 76, 65, ],
'3rd' => [ 56, 0, 45, 76, 58, 52, 13, 48, 54, 68, ],
'4th' => [ 68, 32, 56, 92, 67, 72, 45, 76, 48, 73, ],
'5th' => [ 70, 58, 62, 88, 62, 68, 56, 63, 64, 78, ],
];
$bp = new Boxplot();
$bp->setData($data)
->create('img/BasicUsage.png');
ci7\PhpBoxplot\Boxplot;
$data = [
'1st' => [ 75, 82, 96, 43, 78, 91, 84, 87, 93, ],
'2nd' => [ 66, 74, 62, 100, 72, 68, 59, 76, 65, ],
'3rd' => [ 56, 0, 45, 76, 58, 52, 13, 48, 54, 68, ],
'4th' => [ 68, 32, 56, 92, 67, 72, 45, 76, 48, 73, ],
'5th' => [ 70, 58, 62, 88, 62, 68, 56, 63, 64, 78, ],
];
$bp = new Boxplot();
$bp->setData($data)
->limit(0, 100)
->gridHeightPitch(20)
->gridVerticalOn()
->meanOn()
->jitterOn()
->legendOn()
->labels([ '#1', '#2', '#3', '#4', '#5', ])
->labelX('Achievement Test')
->labelY('Score')
->caption('Achievement Test Results in 2023')
->legends(['Donald Biden'])
->create('img/AdjustDisplayByMethods.png');
ci7\PhpBoxplot\Boxplot;
$dataSet = [
'John' => [
'1st' => [75, 82, 96, 43, 78, 91, 84, 87, 93, ],
'2nd' => [66, 74, 62, 100, 72, 68, 59, 76, 65, ],
'3rd' => [56, 0, 45, 76, 58, 52, 13, 48, 54, 68, ],
'4th' => [68, 32, 56, 92, 67, 72, 45, 76, 48, 73, ],
'5th' => [70, 58, 62, 88, 62, 68, 56, 63, 64, 78, ],
],
'Jake' => [
'test#1' => [62, 35, 48, 43, 56, 78, 32, 24, 29, ],
'test#2' => [37, 92, 56, 36, 14, 86, 41, 58, 47, ],
'test#3' => [49, 83, 0, 48, 64, 73, 50, 46, 38, 92, ],
'test#4' => [53, 44, 34, 51, 74, 68, 53, 86, 24, 66, ],
'test#5' => [83, 61, 55, 96, 87, 46, 21, 19, 88, 68, ],
],
'Hugo' => [
'test01' => [73, 36, 0, 11, 40, 76, 24, 46, 83, ],
'test02' => [69, 42, 76, 8, 92, 84, 45, 34, 67, ],
'test03' => [100, 46, 34, 77, 85, 47, 91, 85, 66, 79, ],
'test04' => [0, 14, 32, 24, 54, 44, 56, 32, 59, 38, ],
'test05' => [69, 84, 65, 42, 33, 80, 74, 54, 75, 56, ],
],
];
$bp = new Boxplot();
$bp->setDataset($dataSet)
->limit(0, 100)
->gridHeightPitch(20)
->gridVerticalOn()
->legendOn()
->meanOn()
->labelX('Achievement Test')
->labelY('Score')
->caption('Achievement Test Results in 2023')
->create('img/MultipleDataSet.png');
ci7\PhpBoxplot\Boxplot;
$bp = new Boxplot();
$bp->config('AdjustDisplayByNeon.neon')
->create('img/AdjustDisplayByNeon.png');
ci7\PhpBoxplot\Boxplot;
$conf = [
'dataSet' => [
'John' => [
'1st' => [75, 82, 96, 43, 78, 91, 84, 87, 93, ],
'2nd' => [66, 74, 62, 100, 72, 68, 59, 76, 65, ],
'3rd' => [56, 0, 45, 76, 58, 52, 13, 48, 54, 68, ],
'4th' => [68, 32, 56, 92, 67, 72, 45, 76, 48, 73, ],
'5th' => [70, 58, 62, 88, 62, 68, 56, 63, 64, 78, ],
],
'Jake' => [
'test#1' => [62, 35, 48, 43, 56, 78, 32, 24, 29, ],
'test#2' => [37, 92, 56, 36, 14, 86, 41, 58, 47, ],
'test#3' => [49, 83, 0, 48, 64, 73, 50, 46, 38, 92, ],
'test#4' => [53, 44, 34, 51, 74, 68, 53, 86, 24, 66, ],
'test#5' => [83, 61, 55, 96, 87, 46, 21, 19, 88, 68, ],
],
'Hugo' => [
'test01' => [73, 36, 0, 11, 40, 76, 24, 46, 83, ],
'test02' => [69, 42, 76, 8, 92, 84, 45, 34, 67, ],
'test03' => [100, 46, 34, 77, 85, 47, 91, 85, 66, 79, ],
'test04' => [0, 14, 32, 24, 54, 44, 56, 32, 59, 38, ],
'test05' => [69, 84, 65, 42, 33, 80, 74, 54, 75, 56, ],
],
],
'limitUpper' => 100,
'limitLower' => 0,
'canvasBackgroundColor' => '#333399',
'axisColor' => '#999999',
'axisWidth' => 2,
'gridHeightPitch' => 10,
'gridVertical' => true,
'whiskerColor' => '#ffff00',
'fontColor' => '#cccccc',
'outlier' => true,
'mean' => true,
'labelX' => 'Achievement Test',
'labelY' => 'Score',
'caption' => 'Adjusting the Display By Array',
'legend' => true,
'legendBackgroundColor' => '#666666',
'legendWidth' => 100,
'legendFontSize' => 10,
];
$bp = new Boxplot();
$bp->config($conf)
->create('img/AdjustDisplayByArray.png');
ci7\PhpBoxplot\Boxplot;
$data = [
'1st' => [75, 82, 96, 43, 78, 91, 84, 87, 93],
'2nd' => [66, 74, 62, 100, 72, 68, 59, 76, 65],
'3rd' => [56, 0, 45, 76, 58, 52, 13, 48, 54, 68],
'4th' => [68, 32, 56, 92, 67, 72, 45, 76, 48, 73],
'5th' => [70, 58, 62, 88, 62, 68, 56, 63, 64, 78],
];
$bp = new Boxplot();
$bp->setData($data)
->config([
// This results in Transparent Background
'canvasBackgroundColor' => null,
])
->limit(0, 100)
->gridHeightPitch(10)
->gridVerticalOn()
->outlierOn()
->meanOn()
->labelX('Examination')
->labelY('Score')
->caption('Transparent Background')
->create('img/TransparentBackground.png');
bash
composer