Top Related Projects
Simple HTML5 Charts using the <canvas> tag
📊 Interactive JavaScript Charts built on SVG
Redefined chart library built with React and D3
Highcharts JS, the JavaScript charting framework
Open-source JavaScript charting library behind Plotly and Dash
Quick Overview
React Chartkick is a React component library for creating beautiful JavaScript charts with minimal code. It provides a simple and intuitive API to create various chart types, including line charts, bar charts, pie charts, and more. The library is built on top of Chart.js and Highcharts, offering flexibility and powerful customization options.
Pros
- Easy to use with a simple and intuitive API
- Supports multiple chart types and customization options
- Integrates well with React applications
- Automatically handles chart updates when data changes
Cons
- Depends on external charting libraries (Chart.js or Highcharts)
- Limited advanced features compared to using Chart.js or Highcharts directly
- May have a steeper learning curve for complex customizations
- Documentation could be more comprehensive for advanced use cases
Code Examples
Creating a line chart:
import { LineChart } from 'react-chartkick'
import 'chartkick/chart.js'
const MyLineChart = () => (
<LineChart data={{"2021-01-01": 11, "2021-01-02": 6, "2021-01-03": 15}} />
)
Creating a pie chart with custom options:
import { PieChart } from 'react-chartkick'
import 'chartkick/chart.js'
const MyPieChart = () => (
<PieChart
data={[["Blueberry", 44], ["Strawberry", 23], ["Banana", 22], ["Apple", 21]]}
donut={true}
legend="bottom"
/>
)
Updating chart data dynamically:
import React, { useState } from 'react'
import { ColumnChart } from 'react-chartkick'
import 'chartkick/chart.js'
const DynamicChart = () => {
const [data, setData] = useState([["Sun", 32], ["Mon", 46], ["Tue", 28]])
const updateData = () => {
setData([["Sun", Math.random() * 50], ["Mon", Math.random() * 50], ["Tue", Math.random() * 50]])
}
return (
<>
<ColumnChart data={data} />
<button onClick={updateData}>Update Data</button>
</>
)
}
Getting Started
-
Install the package:
npm install react-chartkick chart.js
-
Import and use in your React component:
import { LineChart } from 'react-chartkick' import 'chartkick/chart.js' const MyComponent = () => ( <LineChart data={{"2021-01-01": 11, "2021-01-02": 6, "2021-01-03": 15}} /> )
-
Customize as needed using props and options.
Competitor Comparisons
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- More customizable and flexible, offering a wide range of chart types and options
- Better performance for large datasets and complex visualizations
- Extensive documentation and a larger community for support
Cons of Chart.js
- Steeper learning curve, requiring more setup and configuration
- Larger file size, which may impact page load times
- Not specifically designed for React, requiring additional integration work
Code Comparison
React-Chartkick:
import { LineChart } from 'react-chartkick'
import 'chartkick/chart.js'
<LineChart data={{"2017-05-13": 2, "2017-05-14": 5}} />
Chart.js:
import { Line } from 'react-chartjs-2'
<Line
data={{
labels: ['2017-05-13', '2017-05-14'],
datasets: [{ data: [2, 5] }]
}}
/>
React-Chartkick provides a more straightforward API for simple charts, while Chart.js offers more control over chart configuration but requires more setup. Chart.js is better suited for complex visualizations and large datasets, while React-Chartkick excels in quickly creating basic charts with minimal code. The choice between the two depends on the specific project requirements, desired level of customization, and performance needs.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts.js
- More extensive chart types and customization options
- Built-in responsiveness and animation features
- Better performance for large datasets
Cons of ApexCharts.js
- Steeper learning curve due to more complex API
- Larger file size, which may impact load times
- Requires more setup and configuration
Code Comparison
React-Chartkick:
import { LineChart } from 'react-chartkick'
import 'chartkick/chart.js'
<LineChart data={{"2017-05-13": 2, "2017-05-14": 5}} />
ApexCharts.js:
import ReactApexChart from 'react-apexcharts'
<ReactApexChart
options={{
chart: { type: 'line' },
xaxis: { categories: ['2017-05-13', '2017-05-14'] }
}}
series={[{ data: [2, 5] }]}
type="line"
/>
React-Chartkick offers a simpler API for basic charts, while ApexCharts.js provides more control and customization options at the cost of increased complexity. ApexCharts.js is better suited for advanced visualizations and large datasets, while React-Chartkick excels in quickly creating simple charts with minimal setup.
Redefined chart library built with React and D3
Pros of Recharts
- More customizable and flexible, offering a wider range of chart types and styling options
- Built with SVG, providing better performance for complex charts and animations
- Larger community and more frequent updates, resulting in better support and documentation
Cons of Recharts
- Steeper learning curve due to its extensive API and configuration options
- Larger bundle size, which may impact initial load times for applications
Code Comparison
React-Chartkick:
<LineChart data={{"2017-05-13": 2, "2017-05-14": 5, "2017-05-15": 3}} />
Recharts:
<LineChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<Line type="monotone" dataKey="value" stroke="#8884d8" />
</LineChart>
React-Chartkick provides a simpler API for basic charts, requiring less code for common use cases. Recharts offers more granular control over chart elements but requires more verbose code.
Both libraries have their strengths: React-Chartkick excels in simplicity and ease of use, while Recharts provides more advanced features and customization options. The choice between them depends on the specific requirements of your project, such as the complexity of charts needed and the level of customization desired.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive and feature-rich charting library with a wide variety of chart types
- Better performance for large datasets and complex visualizations
- Robust documentation and extensive API for customization
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to its extensive feature set
- Larger file size, which may impact page load times
Code Comparison
react-chartkick:
import { LineChart } from 'react-chartkick'
import 'chartkick/chart.js'
<LineChart data={{"2017-05-13": 2, "2017-05-14": 5}} />
Highcharts:
import Highcharts from 'highcharts'
import HighchartsReact from 'highcharts-react-official'
const options = {
series: [{data: [2, 5]}],
xAxis: {categories: ['2017-05-13', '2017-05-14']}
}
<HighchartsReact highcharts={Highcharts} options={options} />
Summary
react-chartkick is a simpler, more lightweight option for basic charting needs in React applications. It offers easy integration and a straightforward API, making it ideal for quick implementations. Highcharts, on the other hand, provides a more comprehensive charting solution with advanced features and customization options, but comes with a commercial license and a steeper learning curve. The choice between the two depends on the specific requirements of your project, such as the complexity of visualizations needed and budget constraints.
Open-source JavaScript charting library behind Plotly and Dash
Pros of plotly.js
- More extensive and customizable chart types
- Advanced interactivity features like zooming and panning
- Supports 3D visualizations
Cons of plotly.js
- Steeper learning curve due to more complex API
- Larger file size, which may impact page load times
- Requires more setup and configuration for basic charts
Code Comparison
react-chartkick:
import { LineChart } from 'react-chartkick'
import 'chartkick/chart.js'
<LineChart data={{"2017-05-13": 2, "2017-05-14": 5}} />
plotly.js:
import Plot from 'react-plotly.js'
<Plot
data={[{x: ['2017-05-13', '2017-05-14'], y: [2, 5], type: 'scatter'}]}
layout={{width: 320, height: 240, title: 'A Line Chart'}}
/>
Summary
plotly.js offers more advanced features and customization options, making it suitable for complex data visualizations. However, it comes with a steeper learning curve and larger file size. react-chartkick provides a simpler API for basic charts, making it easier to implement quickly, but with fewer advanced options. Choose based on your project's complexity and requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
React Chartkick
Create beautiful JavaScript charts with one line of React
Supports Chart.js, Google Charts, and Highcharts
Quick Start
Run
npm install react-chartkick chart.js
And add
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/chart.js'
This sets up Chartkick with Chart.js. For other charting libraries, see detailed instructions.
Charts
Line chart
<LineChart data={{"2021-01-01": 11, "2021-01-02": 6}} />
Pie chart
<PieChart data={[["Blueberry", 44], ["Strawberry", 23]]} />
Column chart
<ColumnChart data={[["Sun", 32], ["Mon", 46], ["Tue", 28]]} />
Bar chart
<BarChart data={[["Work", 32], ["Play", 1492]]} />
Area chart
<AreaChart data={{"2021-01-01": 11, "2021-01-02": 6}} />
Scatter chart
<ScatterChart data={[[174.0, 80.0], [176.5, 82.3]]} xtitle="Size" ytitle="Population" />
Geo chart - Google Charts
<GeoChart data={[["United States", 44], ["Germany", 23], ["Brazil", 22]]} />
Timeline - Google Charts
<Timeline data={[["Washington", "1789-04-29", "1797-03-03"], ["Adams", "1797-03-03", "1801-03-03"]]} />
Multiple series
data = [
{name: "Workout", data: {"2021-01-01": 3, "2021-01-02": 4}},
{name: "Call parents", data: {"2021-01-01": 5, "2021-01-02": 3}}
];
and
<LineChart data={data} />
Data
Data can be an array, object, callback, or URL.
Array
<LineChart data={[["2021-01-01", 2], ["2021-01-02", 3]]} />
Object
<LineChart data={{"2021-01-01": 2, "2021-01-02": 3}} />
Callback
function fetchData(success, fail) {
success({"2021-01-01": 2, "2021-01-02": 3})
// or fail("Data not available")
}
and
<LineChart data={fetchData} />
URL
Make your pages load super fast and stop worrying about timeouts. Give each chart its own endpoint.
<LineChart data="/stocks" />
Options
Id, width, and height
<LineChart id="users-chart" width="800px" height="500px" />
Min and max values
<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
<LineChart xmin="2021-01-01" xmax="2022-01-01" />
Colors
<LineChart colors={["#b00", "#666"]} />
Stacked columns or bars
<ColumnChart stacked={true} />
Discrete axis
<LineChart discrete={true} />
Label (for single series)
<LineChart label="Value" />
Axis titles
<LineChart xtitle="Time" ytitle="Population" />
Straight lines between points instead of a curve
<LineChart curve={false} />
Show or hide legend
<LineChart legend={true} />
Specify legend position
<LineChart legend="bottom" />
Donut chart
<PieChart donut={true} />
Prefix, useful for currency - Chart.js, Highcharts
<LineChart prefix="$" />
Suffix, useful for percentages - Chart.js, Highcharts
<LineChart suffix="%" />
Set a thousands separator - Chart.js, Highcharts
<LineChart thousands="," />
Set a decimal separator - Chart.js, Highcharts
<LineChart decimal="," />
Set significant digits - Chart.js, Highcharts
<LineChart precision={3} />
Set rounding - Chart.js, Highcharts
<LineChart round={2} />
Show insignificant zeros, useful for currency - Chart.js, Highcharts
<LineChart round={2} zeros={true} />
Friendly byte sizes - Chart.js
<LineChart bytes={true} />
Specify the message when the chart is loading
<LineChart loading="Loading..." />
Specify the message when data is empty
<LineChart empty="No data" />
Refresh data from a remote source every n
seconds
<LineChart refresh={60} />
You can pass options directly to the charting library with:
<LineChart library={{backgroundColor: "#eee"}} />
See the documentation for Google Charts, Highcharts, and Chart.js for more info.
To customize datasets in Chart.js, use:
<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:
Chartkick.options = {
colors: ["#b00", "#666"]
}
Multiple Series
You can pass a few options with a series:
name
data
color
dataset
- Chart.js onlypoints
- Chart.js onlycurve
- 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.
<LineChart download={true} />
Set the filename
<LineChart download="boom" />
Note: Safari will open the image in a new window instead of downloading.
Set the background color
<LineChart download={{background: "#fff"}} />
Installation
Chart.js
Run
npm install react-chartkick chart.js
And add
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/chart.js'
Google Charts
Run
npm install react-chartkick
And add
import Chartkick, { LineChart, PieChart } from 'react-chartkick'
And include on the page
<script src="https://www.gstatic.com/charts/loader.js"></script>
To specify a language or Google Maps API key, use:
Chartkick.configure({language: "de", mapsApiKey: "..."})
Highcharts
Run
npm install react-chartkick highcharts
And add
import { LineChart, PieChart } from 'react-chartkick'
import 'chartkick/highcharts'
No Package Manager
Include the charting library and the Chartkick library
<script src="https://unpkg.com/chart.js@4.2.0/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.0"></script>
<script src="https://unpkg.com/react-chartkick@0.5.3"></script>
Charts are prefixed with ReactChartkick
, like ReactChartkick.LineChart
.
Multiple Libraries
If more than one charting library is loaded, choose between them with:
<LineChart adapter="google" />
Options are google
, highcharts
, and chartjs
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development, run:
git clone https://github.com/ankane/react-chartkick.git
cd react-chartkick
npm install
npm run build
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
📊 Interactive JavaScript Charts built on SVG
Redefined chart library built with React and D3
Highcharts JS, the JavaScript charting framework
Open-source JavaScript charting library behind Plotly and Dash
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot