Socket
Socket
Sign inDemoInstall

chartjs-adapter-date-fns

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-adapter-date-fns

Chart.js adapter to use date-fns for time functionalities


Version published
Maintainers
1
Created

What is chartjs-adapter-date-fns?

The chartjs-adapter-date-fns package is an adapter for Chart.js that allows you to use date-fns for date manipulation and formatting. This package is particularly useful for handling time series data in Chart.js, providing a seamless way to format dates and times on your charts.

What are chartjs-adapter-date-fns's main functionalities?

Date Formatting

This feature allows you to format dates on the x-axis of a Chart.js chart using date-fns. The code sample demonstrates how to set up a line chart with dates parsed and formatted using date-fns.

const Chart = require('chart.js');
const dateFns = require('date-fns');
const adapter = require('chartjs-adapter-date-fns');

const config = {
  type: 'line',
  data: {
    labels: [
      dateFns.parseISO('2023-01-01'),
      dateFns.parseISO('2023-02-01'),
      dateFns.parseISO('2023-03-01')
    ],
    datasets: [{
      label: 'Sample Data',
      data: [10, 20, 30]
    }]
  },
  options: {
    scales: {
      x: {
        type: 'time',
        time: {
          unit: 'month'
        }
      }
    }
  }
};

const ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, config);

Custom Date Parsing

This feature allows you to use custom date parsing logic with date-fns. The code sample shows how to set up a line chart where the dates are parsed using a custom parser function that utilizes date-fns.

const Chart = require('chart.js');
const dateFns = require('date-fns');
const adapter = require('chartjs-adapter-date-fns');

const config = {
  type: 'line',
  data: {
    labels: [
      '2023-01-01',
      '2023-02-01',
      '2023-03-01'
    ],
    datasets: [{
      label: 'Sample Data',
      data: [10, 20, 30]
    }]
  },
  options: {
    scales: {
      x: {
        type: 'time',
        time: {
          parser: date => dateFns.parseISO(date),
          unit: 'month'
        }
      }
    }
  }
};

const ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, config);

Other packages similar to chartjs-adapter-date-fns

Keywords

FAQs

Package last updated on 11 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc