Files
firefly-iii/public/assets/javascript/firefly/gcharts.js

229 lines
6.7 KiB
JavaScript
Raw Normal View History

google.load('visualization', '1.1', {'packages': ['corechart', 'bar', 'sankey', 'table']});
function googleLineChart(URL, container) {
if ($('#' + container).length == 1) {
$.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.LineChart(document.getElementById(container));
/*
Draw it:
*/
chart.draw(gdata, defaultLineChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
} else {
console.log('No container found called "' + container + '"');
}
2014-10-29 10:30:52 +01:00
}
function googleBarChart(URL, container) {
if ($('#' + container).length == 1) {
$.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.charts.Bar(document.getElementById(container));
/*
Draw it:
*/
chart.draw(gdata, defaultBarChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
} else {
console.log('No container found called "' + container + '"');
}
2014-10-29 10:30:52 +01:00
}
function googleColumnChart(URL, container) {
if ($('#' + container).length == 1) {
$.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.charts.Bar(document.getElementById(container));
/*
Draw it:
*/
chart.draw(gdata, defaultColumnChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
} else {
console.log('No container found called "' + container + '"');
}
2014-10-29 10:30:52 +01:00
}
2014-11-07 22:06:30 +01:00
function googleStackedColumnChart(URL, container) {
if ($('#' + container).length == 1) {
$.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');
});
} else {
console.log('No container found called "' + container + '"');
}
2014-11-07 22:06:30 +01:00
}
2014-10-29 10:30:52 +01:00
function googlePieChart(URL, container) {
if ($('#' + container).length == 1) {
$.getJSON(URL).success(function (data) {
/*
Get the data from the JSON
*/
gdata = new google.visualization.DataTable(data);
2014-10-30 18:06:29 +01:00
/*
Format as money
*/
var money = new google.visualization.NumberFormat({
decimalSymbol: ',',
groupingSymbol: '.',
prefix: '\u20AC '
});
for (i = 1; i < gdata.getNumberOfColumns(); i++) {
money.format(gdata, i);
}
2014-10-30 18:06:29 +01:00
/*
Create a new google charts object.
*/
var chart = new google.visualization.PieChart(document.getElementById(container));
2014-10-30 18:06:29 +01:00
/*
Draw it:
*/
chart.draw(gdata, defaultPieChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
} else {
console.log('No container found called "' + container + '"');
}
}
2014-10-30 18:06:29 +01:00
function googleSankeyChart(URL, container) {
if ($('#' + container).length == 1) {
$.getJSON(URL).success(function (data) {
/*
Get the data from the JSON
*/
gdata = new google.visualization.DataTable(data);
2014-10-30 18:06:29 +01:00
/*
Format as money
*/
2014-10-30 18:06:29 +01:00
if (gdata.getNumberOfRows() < 1) {
$('#' + container).parent().parent().remove();
return;
} else if (gdata.getNumberOfRows() < 6) {
defaultSankeyChartOptions.height = 100
} else {
defaultSankeyChartOptions.height = 400
}
2014-10-30 18:06:29 +01:00
/*
Create a new google charts object.
2014-10-30 18:06:29 +01:00
*/
var chart = new google.visualization.Sankey(document.getElementById(container));
2014-10-30 18:06:29 +01:00
/*
Draw it:
2014-10-30 18:06:29 +01:00
*/
chart.draw(gdata, defaultSankeyChartOptions);
}).fail(function () {
$('#' + container).addClass('google-chart-error');
});
} else {
console.log('No container found called "' + container + '"');
}
}