firefly-iii/app/Generator/Chart/PiggyBank/ChartJsPiggyBankChartGenerator.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2015-06-27 13:52:06 -05:00
<?php
namespace FireflyIII\Generator\Chart\PiggyBank;
use Carbon\Carbon;
use Illuminate\Support\Collection;
/**
* Class ChartJsPiggyBankChartGenerator
2015-06-27 13:52:06 -05:00
*
* @package FireflyIII\Generator\Chart\PiggyBank
*/
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
{
/**
* @param Collection $set
*
* @return array
*/
public function history(Collection $set)
{
// language:
2015-12-28 00:12:47 -06:00
$format = trans('config.month_and_day');
2015-06-27 13:52:06 -05:00
$data = [
'count' => 1,
'labels' => [],
'datasets' => [
[
'label' => 'Diff',
2016-01-15 16:12:52 -06:00
'data' => [],
],
2015-06-27 13:52:06 -05:00
],
];
$sum = '0';
bcscale(2);
foreach ($set as $entry) {
$date = new Carbon($entry->date);
$sum = bcadd($sum, $entry->sum);
$data['labels'][] = $date->formatLocalized($format);
$data['datasets'][0]['data'][] = round($sum, 2);
}
return $data;
}
2015-06-28 01:24:12 -05:00
}