Socket
Socket
Sign inDemoInstall

react-chartjs-2

Package Overview
Dependencies
5
Maintainers
4
Versions
84
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-chartjs-2

React components for Chart.js


Version published
Weekly downloads
1.2M
increased by2.72%
Maintainers
4
Install size
55.5 kB
Created
Weekly downloads
 

Package description

What is react-chartjs-2?

The react-chartjs-2 npm package is a React wrapper for Chart.js, a popular JavaScript library for creating simple yet flexible charts. It allows developers to create various types of charts such as line, bar, radar, doughnut, and pie charts, among others, with ease. The package provides React components that encapsulate Chart.js functionality, making it easy to integrate into React applications.

What are react-chartjs-2's main functionalities?

Line Chart

This code sample demonstrates how to create a simple line chart using react-chartjs-2. It includes a dataset for monthly sales and configures the chart to start the y-axis at zero.

{"import { Line } from 'react-chartjs-2';\n\nconst data = {\n  labels: ['January', 'February', 'March', 'April', 'May', 'June'],\n  datasets: [{\n    label: 'Monthly Sales',\n    data: [65, 59, 80, 81, 56, 55],\n    fill: false,\n    borderColor: 'rgb(75, 192, 192)',\n    tension: 0.1\n  }]\n};\n\nconst options = {\n  scales: {\n    y: {\n      beginAtZero: true\n    }\n  }\n};\n\nfunction MyLineChart() {\n  return <Line data={data} options={options} />;\n}"}

Bar Chart

This code sample shows how to create a bar chart with react-chartjs-2. It sets up a dataset with different colors for each bar representing votes for different options.

{"import { Bar } from 'react-chartjs-2';\n\nconst data = {\n  labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],\n  datasets: [{\n    label: 'Votes',\n    data: [12, 19, 3, 5, 2, 3],\n    backgroundColor: [\n      'rgba(255, 99, 132, 0.2)',\n      'rgba(54, 162, 235, 0.2)',\n      'rgba(255, 206, 86, 0.2)',\n      'rgba(75, 192, 192, 0.2)',\n      'rgba(153, 102, 255, 0.2)',\n      'rgba(255, 159, 64, 0.2)'\n    ],\n    borderColor: [\n      'rgba(255, 99, 132, 1)',\n      'rgba(54, 162, 235, 1)',\n      'rgba(255, 206, 86, 1)',\n      'rgba(75, 192, 192, 1)',\n      'rgba(153, 102, 255, 1)',\n      'rgba(255, 159, 64, 1)'\n    ],\n    borderWidth: 1\n  }]\n};\n\nfunction MyBarChart() {\n  return <Bar data={data} />;\n}"}

Doughnut Chart

This code sample illustrates how to create a doughnut chart using react-chartjs-2. It includes a dataset with three segments, each with its own color.

{"import { Doughnut } from 'react-chartjs-2';\n\nconst data = {\n  labels: ['Red', 'Blue', 'Yellow'],\n  datasets: [{\n    data: [300, 50, 100],\n    backgroundColor: [\n      '#FF6384',\n      '#36A2EB',\n      '#FFCE56'\n    ],\n    hoverBackgroundColor: [\n      '#FF6384',\n      '#36A2EB',\n      '#FFCE56'\n    ]\n  }]\n};\n\nfunction MyDoughnutChart() {\n  return <Doughnut data={data} />;\n}"}

Other packages similar to react-chartjs-2

Changelog

Source

5.2.0 (2023-01-09)

Features

  • restore compatability with webpack 4 (#1146) (082c26d)

Readme

Source

react-chartjs-2

Logo

React components for Chart.js, the most popular charting library.

Supports Chart.js v4 and v3.

NPM version Downloads Build status Coverage status Bundle size


Quickstart   •   Docs   •   Slack   •   Stack Overflow

Quickstart

Install this library with peer dependencies:

pnpm add react-chartjs-2 chart.js
# or
yarn add react-chartjs-2 chart.js
# or
npm i react-chartjs-2 chart.js

We recommend using chart.js@^4.0.0.

Then, import and use individual components:

import { Doughnut } from 'react-chartjs-2';

<Doughnut data={...} />

Need an API to fetch data? Consider Cube, an open-source API for data apps.


supported by Cube

Docs

License

MIT Licensed Copyright (c) 2020 Jeremy Ayerst

Keywords

FAQs

Last updated on 09 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc