<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\CommonService;
use App\Service\DefaultService;
class DefaultController extends AbstractController
{
function __construct(CommonService $commonService, DefaultService $defaultService) {
$custInfo = $commonService->custInfo();
$this->counts = $custInfo['counts'];
$this->userinfo = $custInfo['info'];
}
/**
* @Route("/", name="default")
*/
public function index(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
return $this->render('default/index.html.twig', [
'controller_name' => 'HomePage',
'user' => $this->userinfo,
'counts' => $this->counts,
'areas' => $this->buildAreas(),
'pies' => $this->buildPies()
]);
}
private function buildPies() {
$space = 'myPieChart1';
$labels = array('Blue', 'Red', 'Yellow', 'Green');
$data = array(12.21, 15.58, 11.25, 8.32);
$colors = array('#007bff', '#dc3545', '#ffc107', '#28a745');
$charts[] = array('space' => $space, 'labels' => $labels, 'data' => $data, 'colors' => $colors);
$space = 'myPieChart2';
$labels = array('Orange', 'Yellow', 'Green', 'Blue');
$data = array(21.21, 51.58, 1.25, 8.32);
$colors = array('#dc3545', '#ffc107', '#007bff', '#28a745');
$charts[] = array('space' => $space, 'labels' => $labels, 'data' => $data, 'colors' => $colors);
$space = 'myPieChart3';
$labels = array('Yellow', 'Red', 'Green', 'Blue');
$data = array(51.58, 31.21, 19.25, 14.32);
$colors = array('#ffc107', '#dc3545', '#007bff', '#28a745');
$charts[] = array('space' => $space, 'labels' => $labels, 'data' => $data, 'colors' => $colors);
return $charts;
}
private function buildAreas() {
$space = 'myAreaChart1';
$labels = array('Mar 1', 'Mar 2', 'Mar 3', 'Mar 4', 'Mar 5', 'Mar 6', 'Mar 7', 'Mar 8', 'Mar 9', 'Mar 10', 'Mar 11', 'Mar 12', 'Mar 13');
$data = array(10000, 30162, 26263, 18394, 18287, 28682, 31274, 33259, 25849, 24159, 32651, 31984, 38451);
//$colors = array('#007bff', '#dc3545', '#ffc107', '#28a745');
$charts[] = array('space' => $space, 'labels' => $labels, 'data' => $data);
return $charts;
}
}