aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts
diff options
context:
space:
mode:
authorDanijel Anđelković <adanijel99@gmail.com>2022-05-20 04:02:03 +0200
committerDanijel Anđelković <adanijel99@gmail.com>2022-05-20 04:02:03 +0200
commit0d476fb3a73921bbea0994509bc95a19cebae70c (patch)
treea1f2071655b4bd2d78f46c7bb0424a08985664b8 /frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts
parent60d486a636230074350ac19900125098fd07f3f7 (diff)
parent9930bdb624f9511e9f4ead7abd435d25fbdcac4a (diff)
Merge branch 'redesign' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar
Diffstat (limited to 'frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts')
-rw-r--r--frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts47
1 files changed, 30 insertions, 17 deletions
diff --git a/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts b/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts
index c2bd3262..9264e41c 100644
--- a/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts
+++ b/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts
@@ -14,16 +14,16 @@ export class PieChartComponent implements AfterViewInit {
@Input()uniqueValuesPercent?: number[] = [];
updatePieChart(uniqueValues: string[], uniqueValuesPercent: number[]){
- console.log(this.uniqueValues, this.uniqueValuesPercent);
- const newPieChartData = {
- datasets: [{
- label: "Population (millions)",
- backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
- data: [2478,5267,734,784,433],
- }]
-
- }
- };
+ //console.log(this.uniqueValues, this.uniqueValuesPercent);
+ this.pieChartData.datasets = [{
+ label: "%",
+ backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850", "#000000"],
+ data: uniqueValuesPercent,
+ }];
+ this.pieChartData.labels = uniqueValues
+ console.log(this.uniqueValues, this.uniqueValuesPercent);
+ this.myChart?.update()
+ };
@ViewChild('piechart') chartRef!: ElementRef;
constructor() { }
@@ -33,18 +33,31 @@ export class PieChartComponent implements AfterViewInit {
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]
- }]
+ }], labels : [""]
}
+ myChart?: Chart;
ngAfterViewInit(): void {
- const myChart = new Chart(this.chartRef.nativeElement, {
+ let rem = 100;
+ const percents : number[] = []
+ this.uniqueValuesPercent?.forEach(percent => {
+ rem-=percent*100;
+ percents.push(percent*100)
+
+ })
+ const data = {
+ datasets: [{
+ label: "%",
+ backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850", "#000000"],
+ data: [...percents, rem]
+ }], labels : [...this.uniqueValues!,"Ostalo"]
+ }
+
+ const myChart = new Chart(this.chartRef.nativeElement, {
type: 'pie',
- data: this.pieChartData,
+ data: data
+ ,
options: {
- /*title: {
- display: true,
- text: 'Predicted world population (millions) in 2050'
- }*/
plugins:{
legend: {
display: false