Skip to content

Commit

Permalink
handle null chart data
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeseibel committed Dec 23, 2024
1 parent 744d44a commit da7f782
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions coursedashboards/static/coursedashboards/js/graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,13 @@ function renderCoursePercentage1(container, percentages, name_prop, percent_prop
other = 100,
chart_width = 240;

$.each(percentages.splice(0, 9), function () {
data.push([this[name_prop], Math.ceil(this[percent_prop])]);
other -= this[percent_prop];
});

if (percentages) {
$.each(percentages.slice(0, 9), function () {
data.push([this[name_prop], Math.ceil(this[percent_prop])]);
other -= this[percent_prop];
});
}

Highcharts.chart(container, {
chart: {
Expand Down Expand Up @@ -235,21 +238,23 @@ function renderCoursePercentage2(container, percentages, name_prop, percent_prop
categories = [],
other = 100;

$.each(percentages.slice(0, 9), function () {
categories.push(this.major_name);
series.push({
name: this[name_prop],
data: [Math.ceil(this[percent_prop])]
if (percentages) {
$.each(percentages.slice(0, 9), function () {
categories.push(this.major_name);
series.push({
name: this[name_prop],
data: [Math.ceil(this[percent_prop])]
});
other -= this[percent_prop];
});
other -= this[percent_prop];
});

categories.push('Other');
series.push({
name: 'Other',
percent: other,
data: [other]
});
categories.push('Other');
series.push({
name: 'Other',
percent: other,
data: [other]
});
}

Highcharts.chart(container, {
chart: {
Expand Down

0 comments on commit da7f782

Please sign in to comment.