Finished category report.

This commit is contained in:
James Cole
2016-11-17 20:02:55 +01:00
parent 13b96f6136
commit 5088df103f
9 changed files with 367 additions and 199 deletions

View File

@@ -66,57 +66,6 @@ function colorizeData(data) {
return newData;
}
/**
* @param URI
* @param container
* @param chartType
* @param options
* @param colorData
*/
function drawAChart(URI, container, chartType, options, colorData) {
if ($('#' + container).length === 0) {
console.log('No container called ' + container + ' was found.');
return;
}
// var result = true;
// if (options.beforeDraw) {
// result = options.beforeDraw(data, {url: URL, container: container});
// }
// if (result === false) {
// return;
// }
$.getJSON(URI).done(function (data) {
if (colorData) {
data = colorizeData(data);
}
if (allCharts.hasOwnProperty(container)) {
console.log('Will draw updated ' + chartType + ' chart');
allCharts[container].data.datasets = data.datasets;
allCharts[container].data.labels = data.labels;
allCharts[container].update();
} else {
// new chart!
console.log('Will draw new ' + chartType + 'chart');
var ctx = document.getElementById(container).getContext("2d");
allCharts[container] = new Chart(ctx, {
type: chartType,
data: data,
options: options
});
}
}).fail(function () {
console.log('Failed to draw ' + chartType + ' in container ' + container);
$('#' + container).addClass('general-chart-error');
});
console.log('URL for ' + chartType + ' chart : ' + URL);
}
/**
* Function to draw a line chart:
* @param URI
@@ -182,3 +131,60 @@ function pieChart(URI, container) {
drawAChart(URI, container, chartType, options, colorData);
}
/**
* @param URI
* @param container
* @param chartType
* @param options
* @param colorData
*/
function drawAChart(URI, container, chartType, options, colorData) {
if ($('#' + container).length === 0) {
console.log('No container called ' + container + ' was found.');
return;
}
$.getJSON(URI).done(function (data) {
if (data.labels.length === 0) {
console.log(chartType + " chart in " + container + " has no data.");
// remove the chart container + parent
var holder = $('#' + container).parent().parent();
if (holder.hasClass('box')) {
// remove box
holder.remove();
}
return;
}
if (colorData) {
data = colorizeData(data);
}
if (allCharts.hasOwnProperty(container)) {
console.log('Will draw updated ' + chartType + ' chart');
allCharts[container].data.datasets = data.datasets;
allCharts[container].data.labels = data.labels;
allCharts[container].update();
} else {
// new chart!
console.log('Will draw new ' + chartType + 'chart');
var ctx = document.getElementById(container).getContext("2d");
allCharts[container] = new Chart(ctx, {
type: chartType,
data: data,
options: options
});
}
}).fail(function () {
console.log('Failed to draw ' + chartType + ' in container ' + container);
$('#' + container).addClass('general-chart-error');
});
console.log('URL for ' + chartType + ' chart : ' + URL);
}