Some extended code for the category report.

This commit is contained in:
James Cole
2016-11-12 06:48:38 +01:00
parent 32b5a84a0c
commit 6d60d64a82
12 changed files with 716 additions and 20 deletions

View File

@@ -23,6 +23,13 @@ use Illuminate\Support\Collection;
interface CategoryChartGeneratorInterface
{
/**
* @param array $data
*
* @return array
*/
public function pieChart(array $data): array;
/**
* @param Collection $entries
*

View File

@@ -12,6 +12,7 @@
declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Category;
use FireflyIII\Support\ChartColour;
use Illuminate\Support\Collection;
@@ -117,6 +118,30 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
return $data;
}
/**
* @param array $entries
*
* @return array
*/
public function pieChart(array $entries): array
{
$data = [
'datasets' => [
0 => [],
],
'labels' => [],
];
$index = 0;
foreach ($entries as $entry) {
$data['datasets'][0]['data'][] = round($entry['amount'], 2);
$data['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$data['labels'][] = $entry['name'];
$index++;
}
return $data;
}
/**
*
* @param Collection $entries