diff options
author | Nevena Bojovic <nenabojov@gmail.com> | 2022-04-24 18:17:18 +0200 |
---|---|---|
committer | Nevena Bojovic <nenabojov@gmail.com> | 2022-04-24 18:17:18 +0200 |
commit | 0b38d83378e3ea03893eb60729e8bebbf9942949 (patch) | |
tree | 466bd25176a9db067b8adc3682415ef2d3862188 /frontend/src/app/_elements/_charts/pie-chart | |
parent | 8141381f7caefb7b14e02e7a19224c563db4df9b (diff) |
Pie Chart dodat (Test Page).
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 | 27 |
2 files changed, 25 insertions, 4 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 43a2d766..413aa6f3 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 +1 @@ -<p>pie-chart works!</p> +<canvas #piechart width="800" height="450"></canvas> 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 dde5cbab..e7d79615 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 @@ -1,15 +1,36 @@ -import { Component, OnInit } from '@angular/core'; +import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'; +import {Chart} from 'node_modules/chart.js'; @Component({ selector: 'app-pie-chart', templateUrl: './pie-chart.component.html', styleUrls: ['./pie-chart.component.css'] }) -export class PieChartComponent implements OnInit { +export class PieChartComponent implements AfterViewInit { + @ViewChild('piechart') chartRef!: ElementRef; constructor() { } - ngOnInit(): void { + ngAfterViewInit(): void { + const myChart = new Chart(this.chartRef.nativeElement, { + type: 'pie', + data: { + labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], + datasets: [{ + label: "Population (millions)", + backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"], + data: [2478,5267,734,784,433] + }] + }, + /*options: { + title: { + display: true, + text: 'Predicted world population (millions) in 2050' + } + }*/ +}); + } + } |