# react-chartkick

> Create beautiful JavaScript charts with one line of React

Latest version **0.5.4** (published 2024-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-chartkick
pnpm add react-chartkick
yarn add react-chartkick
bun add react-chartkick
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.5.4 |
| Published | 2024-11-16 |
| First published | 2016-08-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1196 |
| Maintainers | ankane |

## Links

- npm: https://www.npmjs.com/package/react-chartkick
- Repository: https://github.com/ankane/react-chartkick
- Homepage: https://github.com/ankane/react-chartkick#readme
- Issues: https://github.com/ankane/react-chartkick/issues
- npm.io page: https://npm.io/package/react-chartkick

## Dependencies (1)

- [chartkick](https://npm.io/package/chartkick.md) >=4.0.0

## Recent versions

- 0.5.4 (latest) — 2024-11-16
- 0.5.3 — 2022-07-24
- 0.5.2 — 2021-09-28
- 0.5.1 — 2021-04-06
- 0.5.0 — 2021-04-05
- 0.4.1 — 2020-07-24
- 0.4.0 — 2019-11-10
- 0.3.3 — 2019-10-28
- 0.3.2 — 2019-07-15
- 0.3.1 — 2019-05-26
- 0.3.0 — 2018-08-09
- 0.2.1 — 2018-06-15
- 0.2.0 — 2018-03-27
- 0.1.7 — 2018-03-25
- 0.1.6 — 2018-01-07
- … 6 more at https://npm.io/package/react-chartkick/versions

## README

# React Chartkick

Create beautiful JavaScript charts with one line of React

[See it in action](https://www.chartkick.com/react)

Supports [Chart.js](https://www.chartjs.org/), [Google Charts](https://developers.google.com/chart/), and [Highcharts](https://www.highcharts.com/)

[![Build Status](https://github.com/ankane/react-chartkick/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/react-chartkick/actions)

## Quick Start

Run

```sh
npm install react-chartkick chart.js
```

And add

```javascript
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/chart.js'
```

This sets up Chartkick with Chart.js. For other charting libraries, see [detailed instructions](#installation).

## Charts

Line chart

```jsx
<LineChart data={{"2025-01-01": 11, "2025-01-02": 6}} />
```

Pie chart

```jsx
<PieChart data={[["Blueberry", 44], ["Strawberry", 23]]} />
```

Column chart

```jsx
<ColumnChart data={[["Sun", 32], ["Mon", 46], ["Tue", 28]]} />
```

Bar chart

```jsx
<BarChart data={[["Work", 32], ["Play", 1492]]} />
```

Area chart

```jsx
<AreaChart data={{"2025-01-01": 11, "2025-01-02": 6}} />
```

Scatter chart

```jsx
<ScatterChart data={[[174.0, 80.0], [176.5, 82.3]]} xtitle="Size" ytitle="Population" />
```

Geo chart - *Google Charts*

```jsx
<GeoChart data={[["United States", 44], ["Germany", 23], ["Brazil", 22]]} />
```

Timeline - *Google Charts*

```jsx
<Timeline data={[["Washington", "1789-04-29", "1797-03-03"], ["Adams", "1797-03-03", "1801-03-03"]]} />
```

Multiple series

```javascript
data = [
  {name: "Workout", data: {"2025-01-01": 3, "2025-01-02": 4}},
  {name: "Call parents", data: {"2025-01-01": 5, "2025-01-02": 3}}
];
```

and

```jsx
<LineChart data={data} />
```

## Data

Data can be an array, object, callback, or URL.

#### Array

```jsx
<LineChart data={[["2025-01-01", 2], ["2025-01-02", 3]]} />
```

#### Object

```jsx
<LineChart data={{"2025-01-01": 2, "2025-01-02": 3}} />
```

#### Callback

```javascript
function fetchData(success, fail) {
  success({"2025-01-01": 2, "2025-01-02": 3})
  // or fail("Data not available")
}
```

and

```jsx
<LineChart data={fetchData} />
```

#### URL

Make your pages load super fast and stop worrying about timeouts. Give each chart its own endpoint.

```jsx
<LineChart data="/stocks" />
```

## Options

Id, width, and height

```jsx
<LineChart id="users-chart" width="800px" height="500px" />
```

Min and max values

```jsx
<LineChart min={1000} max={5000} />
```

`min` defaults to 0 for charts with non-negative values. Use `null` to let the charting library decide.

Min and max for x-axis - *Chart.js*

```jsx
<LineChart xmin="2025-01-01" xmax="2025-02-01" />
```

Colors

```jsx
<LineChart colors={["#b00", "#666"]} />
```

Stacked columns or bars

```jsx
<ColumnChart stacked={true} />
```

Discrete axis

```jsx
<LineChart discrete={true} />
```

Label (for single series)

```jsx
<LineChart label="Value" />
```

Axis titles

```jsx
<LineChart xtitle="Time" ytitle="Population" />
```

Straight lines between points instead of a curve

```jsx
<LineChart curve={false} />
```

Show or hide legend

```jsx
<LineChart legend={true} />
```

Specify legend position

```jsx
<LineChart legend="bottom" />
```

Donut chart

```jsx
<PieChart donut={true} />
```

Prefix, useful for currency - *Chart.js, Highcharts*

```jsx
<LineChart prefix="$" />
```

Suffix, useful for percentages - *Chart.js, Highcharts*

```jsx
<LineChart suffix="%" />
```

Set a thousands separator - *Chart.js, Highcharts*

```jsx
<LineChart thousands="," />
```

Set a decimal separator - *Chart.js, Highcharts*

```jsx
<LineChart decimal="," />
```

Set significant digits - *Chart.js, Highcharts*

```jsx
<LineChart precision={3} />
```

Set rounding - *Chart.js, Highcharts*

```jsx
<LineChart round={2} />
```

Show insignificant zeros, useful for currency - *Chart.js, Highcharts*

```jsx
<LineChart round={2} zeros={true} />
```

Friendly byte sizes - *Chart.js*

```jsx
<LineChart bytes={true} />
```

Specify the message when the chart is loading

```jsx
<LineChart loading="Loading..." />
```

Specify the message when data is empty

```jsx
<LineChart empty="No data" />
```

Refresh data from a remote source every `n` seconds

```jsx
<LineChart refresh={60} />
```

You can pass options directly to the charting library with:

```jsx
<LineChart library={{backgroundColor: "#eee"}} />
```

See the documentation for [Google Charts](https://developers.google.com/chart/interactive/docs/gallery), [Highcharts](https://api.highcharts.com/highcharts), and [Chart.js](https://www.chartjs.org/docs/) for more info.

To customize datasets in Chart.js, use:

```jsx
<LineChart dataset={{borderWidth: 10}} />
```

You can pass this option to individual series as well.

### Global Options

To set options for all of your charts, use:

```javascript
Chartkick.options = {
  colors: ["#b00", "#666"]
}
```

### Multiple Series

You can pass a few options with a series:

- `name`
- `data`
- `color`
- `dataset` - *Chart.js only*
- `points` - *Chart.js only*
- `curve` - *Chart.js only*

### Download Charts

*Chart.js only*

Give users the ability to download charts. It all happens in the browser - no server-side code needed.

```jsx
<LineChart download={true} />
```

Set the filename

```jsx
<LineChart download="boom" />
```

**Note:** Safari will open the image in a new window instead of downloading.

Set the background color

```jsx
<LineChart download={{background: "#fff"}} />
```

## Installation

### Chart.js

Run

```sh
npm install react-chartkick chart.js
```

And add

```javascript
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/chart.js'
```

### Google Charts

Run

```sh
npm install react-chartkick
```

And add

```javascript
import Chartkick, { LineChart, PieChart } from 'react-chartkick'
```

And include on the page

```html
<script src="https://www.gstatic.com/charts/loader.js"></script>
```

To specify a language or Google Maps API key, use:

```js
Chartkick.configure({language: "de", mapsApiKey: "..."})
```

### Highcharts

Run

```sh
npm install react-chartkick highcharts
```

And add

```javascript
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/highcharts'
```

### No Package Manager

Include the charting library and the Chartkick library

```html
<script src="https://unpkg.com/chart.js@4.4.6/dist/chart.umd.js"></script>
<script src="https://unpkg.com/chartjs-adapter-date-fns@3.0.0/dist/chartjs-adapter-date-fns.bundle.js"></script>
<script src="https://unpkg.com/chartkick@5.0.1"></script>
<script src="https://unpkg.com/react-chartkick@0.5.4"></script>
```

Charts are prefixed with `ReactChartkick`, like `ReactChartkick.LineChart`.

### Multiple Libraries

If more than one charting library is loaded, choose between them with:

```jsx
<LineChart adapter="google" />
```

Options are `google`, `highcharts`, and `chartjs`

## History

View the [changelog](https://github.com/ankane/react-chartkick/blob/master/CHANGELOG.md)

## Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

- [Report bugs](https://github.com/ankane/react-chartkick/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/react-chartkick/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features

To get started with development, run:

```sh
git clone https://github.com/ankane/react-chartkick.git
cd react-chartkick
npm install
npm run build
```

---
_Source: https://npm.io/package/react-chartkick · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
