Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
react chart.js time scale does not work with date-fns adapter

I am trying to get the time scale (x axis) work with date-fns adapter and getting "error" for chartjs-adapter-date-fns which could be the issue:

Could not find a declaration file for module 'chartjs-adapter-date-fns'. 'C:/react/envirodata/node_modules/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.js' 
implicitly has an 'any' type.
Try `npm i --save-dev @types/chartjs-adapter-date-fns` if it exists or add a new declaration  (.d.ts) file containing `declare module 'chartjs-adapter-date-fns';`ts(7016)

My setup is like this:

import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  PointElement,
  LineElement,
  Title,
  Tooltip,
  Legend,
} from 'chart.js';

import "chartjs-adapter-date-fns";
import {Line} from 'react-chartjs-2';
import zoomPlugin from "chartjs-plugin-zoom";


ChartJS.register(
  CategoryScale,
  LinearScale,
  PointElement,
  LineElement,
  Title,
  Tooltip,
  Legend, 
  zoomPlugin
);

and the options are like this:

plugins: {
  scales: {
    x: {
        type: 'time',  
        adapters: {
          date: {
              locale: en
          }
        ...

I have tried different date formats for time scale. For example:

  1. labels : [20220224, 20220225...]
  2. data : [{x: 1617253200000, y: 1}, ...]
  3. data : [{x: 2022-02-24, y: 1}, ...]

But nothing seems to work and dates are displayed like as a string. So apart from the chartjs-adapter-date-fns, I am not sure if there is not an issue with setup.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda