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:
Name | Type | Description |
---|---|---|
barWidth | int<0, max> | The width of each bar |
barGap | int<0, max> | The gap between each bar |
groupGap | int<0, max> | The gap between each group |
barStyle | PhpTui\Tui\Style\Style | Style of the bars |
valueStyle | PhpTui\Tui\Style\Style | Style of the values printed at the botton of each bar |
labelStyle | PhpTui\Tui\Style\Style | Style of the labels printed under each bar |
style | PhpTui\Tui\Style\Style | Style for the widget |
data | BarGroup[] | 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) |
direction | PhpTui\Tui\Widget\Direction | Direction of the bars |