diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 5bdaf6f0..13526390 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -609,6 +609,11 @@ class ChartNgCell(CellBase): def add_total_to_line_table(chart, data): # workaround pygal chart.compute_sum = False + + # do not add total for single point + if len(data) <= 1: + return data + data.append(sum(x for x in data if x is not None)) chart.x_labels.append(gettext('Total')) return data diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 81f579ef..9b445429 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -1954,6 +1954,12 @@ def test_table_cell_new_api(app, admin_user, new_api_statistics): resp = app.get(location) assert resp.text.count('Total') == 0 + # no total for single point data + cell.statistic = Statistic.objects.get(slug='empty-x-labels') + cell.save() + resp = app.get(location) + assert resp.text.count('Total') == 0 + def test_dataviz_hourly_unavailable_statistic(statistics, nocache): all_stats_count = Statistic.objects.count()