@lottie
To plot a date/month/year range in Chart.js, you will need to use the built-in time scale in the library. Here's a step-by-step guide on how to do it:
1
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script> |
1
|
<canvas id="myChart"></canvas> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'line', data: { labels: ['01/01/2022', '02/01/2022', '03/01/2022', '04/01/2022', '05/01/2022'], datasets: [{ label: 'Date Range', data: [10, 20, 30, 40, 50], borderColor: 'blue', borderWidth: 1 }] }, options: { scales: { x: { type: 'time', time: { parser: 'MM/DD/YYYY', tooltipFormat: 'll', unit: 'month', displayFormats: { month: 'MMM YYYY' } }, title: { display: true, text: 'Date' } }, y: { title: { display: true, text: 'Value' } } } } }); |
Note: Make sure to replace the sample data and options with your actual data and chart configurations.