From 7f902ffee28010de218b733b10c86d5bba6a83f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Mon, 4 Mar 2019 00:50:27 +0100
Subject: [PATCH] Check if there are abstentions before adding
 'abstentions-bar' to chart

---
 .../shared/statistic/statistic.component.ts          | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/app/components/shared/statistic/statistic.component.ts b/src/app/components/shared/statistic/statistic.component.ts
index a41f01f6f..0f32279f4 100644
--- a/src/app/components/shared/statistic/statistic.component.ts
+++ b/src/app/components/shared/statistic/statistic.component.ts
@@ -133,14 +133,16 @@ export class StatisticComponent implements OnInit {
         this.ccolors[i] = 'rgba(76,175,80, 0.8)';
       }
     }
-    this.ccolors.push('rgba(189,189,189, 0.8)');
-    this.colors.push('rgba(189,189,189, 0.8)');
-    this.translateService.get('statistic.abstentions').subscribe(label => {
-      this.labels.push(label);
-    });
     this.contentService.getAnswer(content.id).subscribe(answer => {
       this.data = answer.roundStatistics[0].independentCounts;
       this.data.push(answer.roundStatistics[0].abstentionCount);
+      if (this.data[this.data.length - 1] > 0) {
+        this.ccolors.push('rgba(189,189,189, 0.8)');
+        this.colors.push('rgba(189,189,189, 0.8)');
+        this.translateService.get('statistic.abstentions').subscribe(label => {
+          this.labels.push(label);
+        });
+      }
       this.createChart(this.colors);
     });
   }
-- 
GitLab