DashboardController.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Attribute\Route;
  6. use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;
  7. use Symfony\UX\Chartjs\Model\Chart;
  8. class DashboardController extends AbstractController
  9. {
  10. #[Route('/dashboard', name: 'app_dashboard')]
  11. public function index(ChartBuilderInterface $chartBuilderInterface): Response
  12. {
  13. $chart = $chartBuilderInterface->createChart(Chart::TYPE_DOUGHNUT);
  14. $chart->setData([
  15. 'labels' => ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  16. 'datasets' => [
  17. [
  18. 'label' => 'My First dataset',
  19. 'backgroundColor' => 'rgb(255, 99, 132)',
  20. 'borderColor' => 'rgb(255, 99, 132)',
  21. 'data' => [0, 10, 5, 2, 20, 30, 45],
  22. ],
  23. ],
  24. ]);
  25. $chart->setOptions([
  26. 'scales' => [
  27. 'y' => [
  28. 'suggestedMin' => 0,
  29. 'suggestedMax' => 100,
  30. ],
  31. ],
  32. ]);
  33. return $this->render('dashboard/index.html.twig', [
  34. 'chart' => $chart,
  35. ]);
  36. }
  37. }