diff options
| author | Danijel Anđelković <adanijel99@gmail.com> | 2022-05-20 04:02:03 +0200 | 
|---|---|---|
| committer | Danijel Anđelković <adanijel99@gmail.com> | 2022-05-20 04:02:03 +0200 | 
| commit | 0d476fb3a73921bbea0994509bc95a19cebae70c (patch) | |
| tree | a1f2071655b4bd2d78f46c7bb0424a08985664b8 /frontend/src/app/_elements/_charts/pie-chart | |
| parent | 60d486a636230074350ac19900125098fd07f3f7 (diff) | |
| parent | 9930bdb624f9511e9f4ead7abd435d25fbdcac4a (diff) | |
Merge branch 'redesign' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar
Diffstat (limited to 'frontend/src/app/_elements/_charts/pie-chart')
| -rw-r--r-- | frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.html | 2 | ||||
| -rw-r--r-- | frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.ts | 47 | 
2 files changed, 31 insertions, 18 deletions
diff --git a/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.html b/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.html index 7faf3af0..fe3998ff 100644 --- a/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.html +++ b/frontend/src/app/_elements/_charts/pie-chart/pie-chart.component.html @@ -1,3 +1,3 @@ -<div class="chart-wrapper"> +<div class="chart-wrapper position-relative">      <canvas #piechart [width]="width" [height]="height"></canvas>  </div>
\ No newline at end of file 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  | 
