<?php
/**
* __ _ ___ ___ ___ ___ ___ ____ _ __ ___ ___
* / _` |/ / / __/ _ \ / _ \ / / / __/| '_ ` _ \ / /
* | (_| |\ \| (_| (_) | (_) |\ \ | (__ | | | | | |\ \
* \__,_|/__/ \___\___/ \___/ /__/ \___\|_| |_| |_|/__/
*
*
************************************************************************************
* @ASCOOS-NAME : ASCOOS CMS 24' *
* @ASCOOS-VERSION : 24.0.0 *
* @ASCOOS-CATEGORY : Framework (Frontend and Administrator Side) *
* @ASCOOS-CREATOR : Drogidis Christos *
* @ASCOOS-SITE : www.ascoos.com *
* @ASCOOS-LICENSE : [Commercial] http://docs.ascoos.com/lics/ascoos/AGL.html *
* @ASCOOS-COPYRIGHT : Copyright (c) 2007 - 2024, AlexSoft Software. *
************************************************************************************
*
* @package : ASCOOS FRAMEWORK Examples
* @subpackage : Creates a histogram from the array data.
* @source : afw-examples\classes\TArrayHandler\Charts\Chart_Histogram.php
* @fileNo :
* @version : 24.0.5
* @created : 2024-12-05 07:00:00 UTC+3
* @updated : 2024-12-10 07:00:00 UTC+3
* @author : Drogidis Christos
* @authorSite : www.alexsoft.gr
* @license : AGL-F
*
* @since PHP 8.2
*/
require_once '../../../autoload.php';
require_once "$afw_path/extras/arrays/TArrayGraphHandler.php";
use ASCOOS\FRAMEWORK\Extras\Arrays\Graphs\TArrayGraphHandler;
/**
* ?????????? flatten ??? ?????????????? ???????
*
* @desc <English> Flatten function for multidimensional arrays.
* @desc <Greek> ?????????? flatten ??? ?????????????? ???????.
*
* @param array $array <English> The multidimensional array to flatten.
* <Greek> ? ????????????? ??????? ??? ?? ??????????.
* @return array <English> The flattened array.
* <Greek> ? ???????? ???????.
*/
function flatten(array $array): array {
$result = [];
array_walk_recursive($array, function($a) use (&$result) { $result[] = $a; });
return $result;
}
/**
* ???????? ?? ???????????? ??????
*
* @desc <English> Data in a multidimensional array.
* @desc <Greek> ???????? ?? ???????????? ??????.
*/
$arrayData = [
[10, 20, 15, 5, 25, 30],
[25, 30, 35, 45],
[35, 40, 45, 50, 55, 60],
[60, 65, 70, 75, 80],
[70, 75, 80, 85, 90, 95],
[90, 95, 100, 105, 110, 115]
];
/**
* ???????? ??????? ?????????
*
* @desc <English> Flat data table.
* @desc <Greek> ???????? ??????? ?????????.
*/
$flatArrayData = flatten($arrayData);
/**
* ???????? ??? ???? ??????
*
* @desc <English> Labels for bins.
* @desc <Greek> ???????? ??? ???? ??????.
*/
$labels = ["10-20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80", "81-90", "91-100", "101-110", "111-120"];
$objArrayGraph = new TArrayGraphHandler($flatArrayData, [
'width' => 800,
'height' => 600,
'backgroundColorIndex' => 1, // 0=Black, 1=White, 2=Red, 3=Green, 4=Blue, 5=Yellow, 6=Cyan, 7=Magenta, 8=Maroon, 9=Dark Green, 10=Navy, 11=Olive, 12=Purple, 13=Teal, 14=Orange, 15=Pink, 16=Indigo, 17=Deep Pink
'barColorIndex' => 2, // ??????? ???????? ??? ?? ?????
'borderColorIndex' => 0, // ??????? ???????? ??? ?? ??????????
'fontPath' => $afw_examples_fonts.'/Murecho/Murecho-Regular.ttf', // ???????? ???? ?? ?????? ??????????????
'labels' => $labels // ???????? ??? ???? ??????
]);
/**
* ?????????? ????????????? ?? 11 ?????????? ??? ?????????? ?? ??????
*
* @desc <English> Create a histogram with 11 bins and save to a file.
* @desc <Greek> ?????????? ????????????? ?? 11 ?????????? ??? ?????????? ?? ??????.
*/
$objArrayGraph->createHistogram(11, 'histogram.png');
/**
* ???????? ??? ??????? ???? ??????
*
* @desc <English> Display the image to the user.
* @desc <Greek> ???????? ??? ??????? ???? ??????.
*/
echo '<img src="histogram.png" alt="Histogram">';
?>
|