<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content="
width
=
device
-width,
initial-scale
=
1
.0">
<
title
>Bar Chart Example</
title
>
<
script
src
=
</
script
>
</
head
>
<
style
>
div {
height: 50vh;
width: 50vw;
}
</
style
>
<
body
>
<
h1
>GeeksForGeeks | Bar Chart Example</
h1
>
<
div
>
<
canvas
id
=
"barChart"
width
=
"400"
height
=
"200"
>
</
canvas
>
</
div
>
<
script
>
// Get the 2D rendering context of the canvas
let ctx =
document.getElementById('barChart').getContext('2d');
// Create a new Bar Chart
let barChart = new Chart(ctx, {
// Specify the chart type
type: 'bar',
// Providing data for the chart
data: {
// Labels for the X-axis
labels: ['January',
'February',
'March',
'April',
'May'],
// Datasets for the chart
datasets: [{
label: 'Pizza', // Label for the dataset
data: [122, 77, 45, 104, 66], // Data points for the Y-axis
backgroundColor: 'rgba(215, 153, 20, 0.5)', // Background color for the bars
borderColor: 'rgba(215, 153, 20, 1)', // Border color for the bars
borderWidth: 1 // Border width for the bars
}, {
label: 'Burger', // Label for the dataset
data: [87, 133, 87, 66, 84], // Data points for the Y-axis
backgroundColor: 'rgba(75, 192, 192, 0.5)', // Background color for the bars
borderColor: 'rgba(75, 192, 192, 1)', // Border color for the bars
borderWidth: 1 // Border width for the bars
}]
},
// Additional options for the chart
options: {
responsive: true, // Make the chart responsive
//Adding Plugin for Chart
plugins: {
//This Plugin will display Title of chart
title: {
display: true,
text: 'Monthly Sales of Pizza and Burger'
}
}
}
});
</
script
>
</
body
>
</
html
>