//TS import { Component } from '@angular/core'; import {Chart, ChartDataset, ChartType} from 'chart.js'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'] }) export class HomeComponent { ngOnInit(): void { this.createChart(); } public chart: any; createChart(){ this.chart = new Chart("barChart", { type: 'bar', 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'], backgroundColor: 'blue' }, { label:"2023", data: ['623','431','525','306','100','369','417','420'], backgroundColor: 'red' } ] } }); } } //HTML <div class="chart-container"> <h2>Product Sales</h2> <canvas id="barChart">{{ chart }}</canvas> </div>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter