<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
title
>Chart.js X-Axis Label Rotation</
title
>
<
script
src
=
</
head
>
<
body
>
<
h1
style
=
"color: green;text-align: center"
>
GeeksforGeeks
</
h1
>
<
canvas
id
=
"myChart"
width
=
"400"
height
=
"200"
>
</
canvas
>
<
script
>
// Example data
const labels =
['January', 'February', 'March', 'April', 'May'];
const data = [10, 20, 15, 25, 20];
document.addEventListener('DOMContentLoaded', function () {
// Get the chart canvas context
let ctx =
document.getElementById('myChart').getContext('2d');
// Create a bar chart
let myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Sample Data',
data: data,
// Green color for bars (RGBA
// format with alpha for transparency)
backgroundColor: 'rgba(0, 128, 0, 0.5)',
// Darker green border
borderColor: 'rgba(0, 128, 0, 1)',
borderWidth: 1
}]
},
options: {
scales: {
x: {
ticks: {
// Maximum rotation angle for tick labels
maxRotation: 45,
// Minimum rotation angle for tick labels
minRotation: 45
}
},
y: {
beginAtZero: true
}
}
}
});
// Add text at the top in green color
ctx.fillStyle = 'rgba(0, 128, 0, 1)';
});
</
script
>
</
body
>
</
html
>