42👍
You need to install and import an adapter, in your case it’s moment adapter for time series
npm install moment chartjs-adapter-moment --save
then import it in your component:
import 'chartjs-adapter-moment';
for more info about adapters, check this
15👍
This answer comes a bit late but for everyone who stumbles here: You need a date adapter. Find a full list here
Once you installed i.e. date-fns via npm install date-fns chartjs-adapter-date-fns --save
in your root directory you have to do two things to make it work in your React project:
- Add this at the top of your file
import 'chartjs-adapter-date-fns';
andimport { enUS } from 'date-fns/locale';
- Inside your options:
options = {
...
scales: {
x: {
type: 'time',
// add this:
adapters: {
date: {
locale: enUS,
},
},
}
},
...
}
- [Chartjs]-How to format x-axis time scale values in Chart.js v2
- [Chartjs]-How to vary the thickness of doughnut chart, using ChartJs.?
12👍
You need an adaptor as stated above. Look here: https://github.com/chartjs/chartjs-adapter-date-fns#cdn
One option is to add the following cdn links:
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
4👍
As stated in your error and the documentation you need an adapter to convert the dates to date objects, see documentation: https://www.chartjs.org/docs/latest/axes/cartesian/time.html#date-adapters
0👍
I think you should put list in x like below code.
scales: {
x: [{
type: 'time'
}]
}