[Chartjs]-Chart js – Chart doesn't show when x axis has type 'time'

3👍

From the docs:

Date Adapters
The time scale requires both a date library and a
corresponding adapter to be present. Please choose from the
available adapters.

So you can change your HTML like this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js" integrity="sha512-ElRFoEQdI5Ht6kZvyzXhYG9NqjtkmlkfYk0wr6wHxU9JEHakS7UJZNeml5ALk+8IKlU6jDgMabC3vkumRokgJA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@^2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script>


<canvas id="mychart"></canvas>

and then you’ll be able to use type: "time" for x axis.
time for x axis

Leave a comment