pie-chart component ts and html - 2023 Reporting

PHOTO EMBED

Mon Jun 17 2024 13:26:04 GMT+0000 (Coordinated Universal Time)

Saved by @iamkatmakhafola

//TS
import { Component } from '@angular/core';
import {Chart, ChartDataset, ChartType} from 'chart.js';

@Component({
  selector: 'app-pie-chart',
  templateUrl: './pie-chart.component.html',
  styleUrls: ['./pie-chart.component.scss']
})
export class PieChartComponent {
  ngOnInit(): void {
    this.createChart();
  }
  public chart: any;
  createChart(){
    this.chart = new Chart("pie-chart", {
      type: 'pie',
      data: {
        labels: ['Shirt', 'Jacket', 'Men Tops', 'Men Pants', 
                 'Swimwear', 'Shoes', 'Sleepwear', 'Men Accessories'],
        datasets:[
          {
            label:"2022",
            data: ['446','551','462','158','171','553','566','231']
          },
          {
            label:"2023",
            data: ['623','431','525','306','100','369','417','420']
          }
        ]
      }
    });
  }
}
//HTML
<div class="chart-container">
    <h2>Product Sales</h2>
    <canvas id="pie-chart">{{ chart }}</canvas>
</div>
content_copyCOPY

2023 - pie-chart component ts and html: 1.4 In the “pie-chart.component.ts”: a. Create a method for the pie chart. This should include the data and labels for the pie chart. 1.5 In the “pie-chart.component.html”: a. The pie chart should have a header titled “Product Sales”. b. Create a container and use angular string interpolation to render the pie chart variable.