<?php

namespace App\Service;

use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;
use Symfony\UX\Chartjs\Model\Chart;

class ChartJs
{
    private function getOptions(string $title) :array
    {
        return
            [
                'title'=>[
                    'display'=>true,
                    'fontColor' => "#000040",
                    'text'  => $title,

                ],
                'legend'=> [
                    'display'=>false
                ],
                'scales' => [
                    'yAxes' => [
                        ['ticks' =>
                            [
                                'min' => 0,
                                'fontColor' => "#000040",
                                'fontSize' => 14
                            ]
                        ],
                    ],
                    'xAxes' => [
                        ['ticks' =>
                            [
                                'fontColor' => "#000040",
                                'fontSize' => 14
                            ]
                        ],
                    ],
                ],

            ];

    }

    private function createChart(
        ChartBuilderInterface $chartBuilder,
        array $label,
        array $data,
        string $title) : Chart
    {
        $chart = $chartBuilder->createChart(Chart::TYPE_LINE);
        $chart->setData([
            'labels' => $label,

            'datasets' => [
                [
                    'fill'          => false,
                    'borderColor'   => 'rgb(75, 192, 192)',
                    'data'          => $data,
                    'tension'       => 0.1
                ]
            ]
        ]);
        $chart->setOptions($this->getOptions($title));
        return $chart;
    }
}