diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index 571ec2fb69..fb76aecc18 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -124,15 +124,19 @@ class GoogleChartController extends BaseController
$end->endOfYear();
$income = 0;
$expense = 0;
+ $count = 0;
while ($start < $end) {
// total income:
$income += $tj->getSumOfIncomesByMonth($start);
$expense += $tj->getSumOfExpensesByMonth($start);
+ $count++;
$start->addMonth();
}
$chart->addRow('Sum', $income, $expense);
+ $count = $count > 0 ? $count : 1;
+ $chart->addRow('Average', ($income / $count), ($expense / $count));
$chart->generate();
@@ -140,6 +144,53 @@ class GoogleChartController extends BaseController
}
+
+ /**
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function budgetsReportChart($year)
+ {
+
+ try {
+ $start = new Carbon('01-01-' . $year);
+ } catch (Exception $e) {
+ App::abort(500);
+ }
+
+ /** @var \Grumpydictator\Gchart\GChart $chart */
+ $chart = App::make('gchart');
+
+ /** @var \FireflyIII\Database\Budget $bdt */
+ $bdt = App::make('FireflyIII\Database\Budget');
+ $budgets = $bdt->get();
+
+ $chart->addColumn('Month', 'date');
+ /** @var \Budget $budget */
+ foreach ($budgets as $budget) {
+ $chart->addColumn($budget->name, 'number');
+ }
+
+ /*
+ * Loop budgets this year.
+ */
+ $end = clone $start;
+ $end->endOfYear();
+ while ($start <= $end) {
+ $row = [clone $start];
+
+ foreach($budgets as $budget) {
+ $row[] = $bdt->spentInMonth($budget, $start);
+ }
+
+ $chart->addRowArray($row);
+ $start->addMonth();
+ }
+
+
+ $chart->generate();
+ return Response::json($chart->getData());
+ }
+
/**
* @return \Illuminate\Http\JsonResponse
*/
diff --git a/app/routes.php b/app/routes.php
index 5a1b2b5223..72486627ee 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -168,6 +168,7 @@ Route::group(
Route::get('/chart/sankey/{account}/in', ['uses' => 'GoogleChartController@accountSankeyInChart']);
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
+ Route::get('/chart/reports/budgets/{year}', ['uses' => 'GoogleChartController@budgetsReportChart']);
// google table controller
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);
diff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.php
index 9ab2207b83..ffbd8ab0cc 100644
--- a/app/views/reports/year.blade.php
+++ b/app/views/reports/year.blade.php
@@ -25,7 +25,7 @@
-
+
Summary
@@ -33,8 +33,8 @@
|
- @foreach($summary as $entry)
- {{$entry['month']}} |
+ @foreach($summary as $entry)
+ {{$entry['month']}} |
@endforeach
Sum |
@@ -67,6 +67,19 @@
+
+
@stop
@section('scripts')
diff --git a/public/assets/javascript/firefly/gcharts.js b/public/assets/javascript/firefly/gcharts.js
index 9b2f2c3940..b17ab935e1 100644
--- a/public/assets/javascript/firefly/gcharts.js
+++ b/public/assets/javascript/firefly/gcharts.js
@@ -89,6 +89,35 @@ function googleColumnChart(URL, container) {
});
}
+function googleStackedColumnChart(URL, container) {
+ $.getJSON(URL).success(function (data) {
+ /*
+ Get the data from the JSON
+ */
+ gdata = new google.visualization.DataTable(data);
+
+ /*
+ Format as money
+ */
+ var money = new google.visualization.NumberFormat({decimalSymbol: ',', groupingSymbol: '.', prefix: '\u20AC '});
+ for (i = 1; i < gdata.getNumberOfColumns(); i++) {
+ money.format(gdata, i);
+ }
+
+ /*
+ Create a new google charts object.
+ */
+ var chart = new google.visualization.ColumnChart(document.getElementById(container));
+ /*
+ Draw it:
+ */
+ chart.draw(gdata, defaultStackedColumnChartOptions);
+
+ }).fail(function () {
+ $('#' + container).addClass('google-chart-error');
+ });
+}
+
function googlePieChart(URL, container) {
$.getJSON(URL).success(function (data) {
/*
diff --git a/public/assets/javascript/firefly/gcharts.options.js b/public/assets/javascript/firefly/gcharts.options.js
index 71e8193561..db138b0c14 100644
--- a/public/assets/javascript/firefly/gcharts.options.js
+++ b/public/assets/javascript/firefly/gcharts.options.js
@@ -12,7 +12,6 @@ var defaultLineChartOptions = {
height: '80%'
},
height: 400,
- vAxis: {format: '\u20AC #'},
colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
hAxis: {
textStyle: {
@@ -29,7 +28,8 @@ var defaultLineChartOptions = {
color: '#838383',
fontName: 'Roboto2',
fontSize: '12'
- }
+ },
+ format: '\u20AC #'
}
@@ -65,6 +65,40 @@ var defaultColumnChartOptions = {
},
};
+var defaultStackedColumnChartOptions = {
+ height: 400,
+ chartArea: {
+ left: 50,
+ top: 10,
+ width: '85%',
+ height: '80%'
+ },
+ vAxis: {format: '\u20AC #'},
+ legend: {
+ position: 'none'
+ },
+ isStacked: true,
+ colors: ["#4285f4", "#db4437", "#f4b400", "#0f9d58", "#ab47bc", "#00acc1", "#ff7043", "#9e9d24", "#5c6bc0", "#f06292", "#00796b", "#c2185b"],
+ vAxis: {
+ textStyle: {
+ color: '#838383',
+ fontName: 'Roboto2',
+ fontSize: '12'
+ },
+ format: '\u20AC #'
+ },
+ hAxis: {
+ textStyle: {
+ color: '#838383',
+ fontName: 'Roboto2',
+ fontSize: '12'
+ },
+ gridlines: {
+ color: 'transparent'
+ }
+ },
+};
+
var defaultPieChartOptions = {
chartArea: {
left: 0,
diff --git a/public/assets/javascript/firefly/reports.js b/public/assets/javascript/firefly/reports.js
index 445304a04c..6977f38f57 100644
--- a/public/assets/javascript/firefly/reports.js
+++ b/public/assets/javascript/firefly/reports.js
@@ -4,4 +4,5 @@ google.setOnLoadCallback(drawChart);
function drawChart() {
googleColumnChart('chart/reports/income-expenses/' + year, 'income-expenses-chart');
googleColumnChart('chart/reports/income-expenses-sum/' + year, 'income-expenses-sum-chart')
+ googleStackedColumnChart('chart/reports/budgets/' + year, 'budgets');
}
\ No newline at end of file