Socket
Socket
Sign inDemoInstall

chartjs-adapter-moment

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chartjs-adapter-moment

Chart.js adapter to use Moment.js for time functionalities


Version published
Weekly downloads
87K
decreased by-21.61%
Maintainers
2
Weekly downloads
 
Created

What is chartjs-adapter-moment?

The chartjs-adapter-moment package is an adapter for Chart.js that allows you to use Moment.js for date manipulation and formatting. This is particularly useful for creating time-based charts where you need to handle dates and times efficiently.

What are chartjs-adapter-moment's main functionalities?

Date Formatting

This feature allows you to format dates on the x-axis of your Chart.js charts using Moment.js. The code sample demonstrates how to create a line chart with dates formatted as 'll' (localized date format).

const chart = new Chart(ctx, {
  type: 'line',
  data: {
    datasets: [{
      data: [{ x: '2023-01-01', y: 10 }, { x: '2023-01-02', y: 20 }]
    }]
  },
  options: {
    scales: {
      x: {
        type: 'time',
        time: {
          unit: 'day',
          tooltipFormat: 'll'
        }
      }
    }
  }
});

Date Parsing

This feature allows you to parse dates using Moment.js before they are displayed on the chart. The code sample shows how to parse dates in 'YYYY-MM-DD' format and use them in a line chart.

const chart = new Chart(ctx, {
  type: 'line',
  data: {
    datasets: [{
      data: [{ x: moment('2023-01-01', 'YYYY-MM-DD'), y: 10 }, { x: moment('2023-01-02', 'YYYY-MM-DD'), y: 20 }]
    }]
  },
  options: {
    scales: {
      x: {
        type: 'time',
        time: {
          parser: 'YYYY-MM-DD'
        }
      }
    }
  }
});

Custom Time Units

This feature allows you to customize the time units displayed on the x-axis. The code sample demonstrates how to set the time unit to 'week' for a line chart.

const chart = new Chart(ctx, {
  type: 'line',
  data: {
    datasets: [{
      data: [{ x: '2023-01-01', y: 10 }, { x: '2023-01-02', y: 20 }]
    }]
  },
  options: {
    scales: {
      x: {
        type: 'time',
        time: {
          unit: 'week'
        }
      }
    }
  }
});

Other packages similar to chartjs-adapter-moment

Keywords

FAQs

Package last updated on 21 Nov 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