Files
firefly-iii/public/js/ff/reports/default/year.js

86 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-10-25 18:53:54 +02:00
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
2016-06-27 16:11:49 +02:00
var chartDrawn;
var budgetChart;
$(function () {
"use strict";
2016-06-27 16:11:49 +02:00
chartDrawn = false;
drawChart();
});
2015-05-08 17:13:49 +02:00
function drawChart() {
2015-05-24 20:41:14 +02:00
"use strict";
2016-02-18 10:04:53 +01:00
lineChart('chart/report/net-worth/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'net-worth');
2015-12-14 20:37:38 +01:00
columnChart('chart/report/in-out/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-chart');
columnChart('chart/report/in-out-sum/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-sum-chart');
2016-04-24 20:00:20 +02:00
2016-06-16 20:52:30 +02:00
$('.budget-chart-activate').on('click', clickBudgetChart);
2015-03-10 17:26:31 +01:00
}
2015-05-16 07:28:58 +02:00
2016-06-16 20:52:30 +02:00
function clickBudgetChart(e) {
"use strict";
var link = $(e.target);
var budgetId = link.data('budget');
2016-06-27 16:11:49 +02:00
var URL = 'chart/budget/period/' + budgetId + '/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds;
var container = 'budget_chart';
// if chart drawn is false, draw the first one, then
// set to true
if (chartDrawn == false) {
// do new chart:
$.getJSON(URL).done(function (data) {
console.log('Will draw new columnChart(' + URL + ')');
var ctx = document.getElementById(container).getContext("2d");
var newData = {};
newData.datasets = [];
for (var i = 0; i < data.count; i++) {
newData.labels = data.labels;
var dataset = data.datasets[i];
dataset.backgroundColor = fillColors[i];
newData.datasets.push(dataset);
}
// completely new chart.
budgetChart = new Chart(ctx, {
type: 'bar',
data: data,
options: defaultColumnOptions
});
}).fail(function () {
$('#' + container).addClass('general-chart-error');
});
console.log('URL for column chart : ' + URL);
chartDrawn = true;
} else {
console.log('Will now handle remove data and add new!');
$.getJSON(URL).done(function (data) {
console.log('Will draw updated columnChart(' + URL + ')');
var newData = {};
newData.datasets = [];
for (var i = 0; i < data.count; i++) {
newData.labels = data.labels;
var dataset = data.datasets[i];
dataset.backgroundColor = fillColors[i];
newData.datasets.push(dataset);
}
// update the chart
console.log('Now update chart thing.');
budgetChart.data.datasets = newData.datasets;
budgetChart.update();
}).fail(function () {
$('#' + container).addClass('general-chart-error');
});
}
2015-05-16 07:28:58 +02:00
return false;
}