React Components for the popular chart library Chart.js
  • JavaScript 55.5%
  • TypeScript 34.2%
  • CSS 6.9%
  • HTML 3.4%
Find a file
2021-01-22 16:42:37 -06:00
.github/workflows Create main.yml 2020-06-20 09:48:35 -05:00
example Renamed to react-chart.js. Updated examples 2020-04-23 14:53:43 -05:00
src Hotfix on no rerender after canvas update 2020-04-22 15:33:22 -05:00
.editorconfig Initial updates 2020-04-21 16:52:02 -05:00
.eslintignore init create-react-library@3.0.8 2020-04-21 14:57:42 -05:00
.eslintrc init create-react-library@3.0.8 2020-04-21 14:57:42 -05:00
.gitignore updated tests 2020-04-22 09:55:46 -05:00
.prettierrc Initial updates 2020-04-21 16:52:02 -05:00
.travis.yml init create-react-library@3.0.8 2020-04-21 14:57:42 -05:00
package-lock.json lockfile to v2 2021-01-22 16:42:37 -06:00
package.json lockfile to v2 2021-01-22 16:42:37 -06:00
README.md Update README.md 2020-08-10 12:53:55 -05:00
tsconfig.json Initial updates 2020-04-21 16:52:02 -05:00
tsconfig.test.json init create-react-library@3.0.8 2020-04-21 14:57:42 -05:00

@jhonnold/react-chart.js

NPM downloads build status license

React Components for the popular Chart.js libary

Install

npm install --save @jhonnold/react-chart.js chart.js
chart.js is a peer-dependency and must be installed alongside this library

Getting Started

import { BarChart } from '@jhonnold/react-chart.js';

<BarChart data={...} />

General

Direct examples of each chart type can be found in examples.

Live Examples: Github Pages

Components

import ChartComponent, {
    LineChart,
    BarChart,
    HorizontalBarChart,
    RadarChart,
    DoughnutChart,
    PolarAreaChart,
    BubbleChart,
    PieChart,
    ScatterChart,
} from '@jhonnold/react-chart.js';

Configure

Props

const {
    id,         // string
    height,     // number
    width,      // number
    redraw,     // boolean
    type,       // string (required only on ChartComponent)
    data,       // chart.js dataObj or fn that returns dataObj (required)
    options,    // chart.js options
    plugins,    // chart.js plugins
} = props;

id

Type: string Default: undefined

ID attribute applied to the rendered canvas

height

Type: number Default: 150

Height attribute applied to the rendered canvas

width

Type: number Default: 300

Width attribute applied to the rendered canvas

redraw

Type: boolean Default: false

If true, will tear down and redraw chart on all updates

type

Type: 'line' | 'bar' | 'horizontalBar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'

Chart.js chart type (required only on ChartComponent)

data (required)

Type: ((canvas: HTMLCanvasElement | null): Chart.ChartData) | Chart.ChartData

The data object that is passed into the Chart.js chart (more info).

This can also be a function, that receives a canvas element and returns the data object.

const data = canvas => {
    const ctx = canvas.getContext('2d');
    const g = ctx.createLinearGradient(...);

    // ...

    return {
        datasets: [{
            backgroundColor: g,
            //. ..
        }],
        // ...
    };
}

options

Type: Chart.ChartOptions

The options object that is passed into the Chart.js chart (more info)

plugins

Type: Chart.PluginServiceRegistrationOptions[]

The plugins array that is passed into the Chart.js chart (more info)

License

MIT © jhonnold