<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Chart.js Line Chart with Linear X-axis</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
</style>
</head>
<body>
<div style="width:80%;">
<canvas id="myChart"></canvas>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const data = {
datasets: [{
label: 'Monthly Sales',
data: [
{ x: 1, y: 50 },
{ x: 2, y: 75 },
{ x: 3, y: 120 },
{ x: 4, y: 90 },
{ x: 5, y: 100 },
],
borderColor: 'purple',
borderWidth: 2,
fill: false,
}],
};
const config = {
type: 'line',
data: data,
options: {
plugins: {
legend: {
display: false,
},
},
elements: {
line: {
tension: 0,
},
},
scales: {
x: {
type: 'linear',
position: 'bottom',
grid: {
color: 'red',
borderColor: 'blue',
tickColor: 'grey'
},
},
y: {
// You can customize the y-axis if needed
},
},
},
};
const chart = new Chart(document.getElementById('myChart'), config);
});
</script>
</body>
</html>