code share below:
html
<div>
<canvas baseChart
[data]="pieChartData"
[colors]="colors"
[labels]="pieChartLabels"
[chartType]="pieChartType"
>
</canvas>
</div>
component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-pie-chart',
templateUrl: './pie-chart.component.html',
styleUrl: './pie-chart.component.css'
})
export class PieChartComponent implements OnInit {
pieChartData: number[] = [350,450,120];
pieChartLabels: string[] = ['xyz','Logistics','Main st Bakery','Acme hosting'];
colors: any[] = [
{
backgroundColor: ['#26547c','#ff6b6b','#ffd166']
}
];
pieChartType = 'pie'
constructor(){}
ngOnInit(){
}
}
i want make pie graph
After going through the
demo pie chartBelow is a working example of pie chart generated throughng2-chartspackage. The following changes were made!chartTypein HTML needs to betypeinstead.backgroundColorneed to be set inside thedatasetsarray, instead ofcolorsattribute in the htmlpieChartDataneeds to be restructured to contain the datasets within itcode
stackblitz