//TS
import { Component } from '@angular/core';
import { Chart } from 'chart.js';
@Component({
selector: 'app-bar-line',
templateUrl: './bar-line.component.html',
styleUrls: ['./bar-line.component.scss']
})
export class BarLineComponent {
ngOnInit(): void {
this.createChart();
}
public chart: any;
createChart(){
this.chart = new Chart("bar-line", {
type: 'line',
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']
},
{
type:'bar',
label:"2023",
data: ['623','431','525','306','100','369','417','420']
}
]
}
});
}
}
//HTML
<div class="chart-container">
<h2>Product Sales</h2>
<canvas id="bar-line">{{ 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