-
-
Save devfabriciobr/8b3cf0f1c0f949cbd01d5053fde0c41a to your computer and use it in GitHub Desktop.
CLASSE MODIFICADA TBarChart (ADIANTI FRAMEWORK)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| #COMPONENTE TBarChart.php (lib\adianti\widget\chart\TBarChart.php) | |
| namespace Adianti\Widget\Chart; | |
| use Adianti\Widget\Base\TElement; | |
| use Adianti\Widget\Base\TScript; | |
| use Exception; | |
| class TBarChart extends TChartBase | |
| { | |
| private $xlabels; | |
| private $ylabel; | |
| private $datasets; | |
| private $horizontal; | |
| private $stack; | |
| public function setXLabels($labels) | |
| { | |
| $this->xlabels = $labels; | |
| } | |
| public function setYLabel($label) | |
| { | |
| $this->ylabel = $label; | |
| } | |
| public function makeHorizontal() | |
| { | |
| $this->horizontal = true; | |
| } | |
| public function makeStack() | |
| { | |
| $this->stack = true; | |
| } | |
| public function addDataset($name, $data) | |
| { | |
| $this->datasets[$name] = $data; | |
| } | |
| public function show() | |
| { | |
| $template = file_get_contents('lib/adianti/include/components/tbarchart/tbarchart.html'); | |
| $template = str_replace('{chart_id}', uniqid(), $template); | |
| $template = str_replace('{title}', (string) $this->title, $template); | |
| $template = str_replace('{data}', json_encode($this->datasets), $template); | |
| $template = str_replace('{xlabels}', json_encode($this->xlabels), $template); | |
| $template = str_replace('{height}', $this->height, $template); | |
| $template = str_replace('{indexAxis}', ((bool) $this->horizontal ? 'y' : 'x'), $template); | |
| $template = str_replace('{scales}', json_encode( $this->stack ? (object) [ 'x' => ['stacked'=>true], 'y' => ['stacked'=>true]] : (object) []), $template); | |
| $template = str_replace('{numberPrefix}', $this->numberPrefix, $template); | |
| $template = str_replace('{decimals}', $this->numericMask[0], $template); | |
| $template = str_replace('{decimalsSeparator}', $this->numericMask[1], $template); | |
| $template = str_replace('{thousandSeparator}', $this->numericMask[2], $template); | |
| $colors = parent::getColors(); | |
| $datasets = []; | |
| $i = 0; | |
| if (!empty($this->datasets)) | |
| { | |
| foreach ($this->datasets as $name => $values) | |
| { | |
| $color = $colors[$i]; | |
| if ($name == 'Entradas') { | |
| $color = '#139865ff'; | |
| } | |
| if ($name == 'Saídas') { | |
| $color = '#e37068ff'; | |
| } | |
| $datasets[] = ['label' => $name, 'data' => $values, 'backgroundColor' => $color]; | |
| $i++; | |
| } | |
| } | |
| $template = str_replace('{datasets}', json_encode($datasets), $template); | |
| parent::add($template); | |
| parent::show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment