Bar Chart

Bar Chart #

PhpTui\Tui\Extension\Core\Widget\BarChartWidget

Example #

Show code
<?php

declare(strict_types=1);

use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\BarChart\BarGroup;
use PhpTui\Tui\Extension\Core\Widget\BarChartWidget;
use PhpTui\Tui\Style\Style;
use PhpTui\Tui\Text\Line;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    BarChartWidget::default()
        ->barWidth(10)
        ->barStyle(Style::default()->red())
        ->groupGap(5)
        ->data(
            BarGroup::fromArray([
                '1' => 12,
                '2' => 15,
                '3' => 13,
            ])->label(Line::fromString('md5')),
            BarGroup::fromArray([
                '1' => 22,
                '2' => 15,
                '3' => 23,
            ])->label(Line::fromString('sha256')),
        )
);

Parameters #

Configure the widget using the builder methods named as follows:

NameTypeDescription
barWidthint<0, max>The width of each bar
barGapint<0, max>The gap between each bar
groupGapint<0, max>The gap between each group
barStylePhpTui\Tui\Style\StyleStyle of the bars
valueStylePhpTui\Tui\Style\StyleStyle of the values printed at the botton of each bar
labelStylePhpTui\Tui\Style\StyleStyle of the labels printed under each bar
stylePhpTui\Tui\Style\StyleStyle for the widget
dataBarGroup[]Array of groups containing the bars
max?int<0, max>Value necessary for a bar to reach the maximum height (if no value is specified, the maximum value in the data is taken as reference)
directionPhpTui\Tui\Widget\DirectionDirection of the bars