Convert Figma logo to code with AI

TanStack logoreact-charts

⚛️ Simple, immersive & interactive charts for React

2,946
241
2,946
70

Top Related Projects

23,884

Redefined chart library built with React and D3

64,568

Simple HTML5 Charts using the <canvas> tag

📊 Interactive JavaScript Charts built on SVG

13,142

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

10,987

A collection of composable React components for building interactive data visualizations

Highcharts JS, the JavaScript charting framework

Quick Overview

TanStack/react-charts is a powerful and flexible data visualization library for React. It provides a comprehensive set of tools for creating high-quality, customizable charts and graphs within React-based applications.

Pros

  • Extensive Charting Options: The library offers a wide range of chart types, including line charts, bar charts, scatter plots, pie charts, and more, allowing developers to choose the most appropriate visualization for their data.
  • Customizability: The library provides a high degree of customizability, enabling developers to fine-tune the appearance and behavior of the charts to match the branding and design of their applications.
  • Performance: TanStack/react-charts is designed for performance, with efficient rendering and support for large datasets, making it suitable for data-intensive applications.
  • Accessibility: The library includes built-in accessibility features, ensuring that the charts are accessible to users with disabilities.

Cons

  • Learning Curve: The library has a relatively steep learning curve, especially for developers who are new to data visualization or the TanStack ecosystem.
  • Limited Community Support: Compared to some other popular data visualization libraries for React, TanStack/react-charts has a smaller community, which may result in fewer resources and less community support.
  • Dependency on TanStack: The library is part of the TanStack ecosystem, which means that developers who are not familiar with the TanStack ecosystem may need to invest time in learning the overall ecosystem.
  • Limited Integrations: The library may not have as many pre-built integrations with other popular data sources or tools as some other data visualization libraries.

Code Examples

Creating a Line Chart

import { LineChart } from '@tanstack/react-charts';

const data = [
  { x: 1, y: 10 },
  { x: 2, y: 20 },
  { x: 3, y: 15 },
  { x: 4, y: 25 },
];

const MyLineChart = () => {
  return (
    <LineChart
      data={data}
      xAccessor={(d) => d.x}
      yAccessor={(d) => d.y}
    />
  );
};

Customizing a Bar Chart

import { BarChart } from '@tanstack/react-charts';

const data = [
  { category: 'A', value: 10 },
  { category: 'B', value: 20 },
  { category: 'C', value: 15 },
  { category: 'D', value: 25 },
];

const MyBarChart = () => {
  return (
    <BarChart
      data={data}
      categoryAccessor={(d) => d.category}
      valueAccessor={(d) => d.value}
      barStyle={{
        fill: 'blue',
        stroke: 'black',
        strokeWidth: 1,
      }}
    />
  );
};

Adding Interactivity to a Scatter Plot

import { ScatterChart } from '@tanstack/react-charts';

const data = [
  { x: 1, y: 10, label: 'Point A' },
  { x: 2, y: 20, label: 'Point B' },
  { x: 3, y: 15, label: 'Point C' },
  { x: 4, y: 25, label: 'Point D' },
];

const MyScatterChart = () => {
  return (
    <ScatterChart
      data={data}
      xAccessor={(d) => d.x}
      yAccessor={(d) => d.y}
      labelAccessor={(d) => d.label}
      onPointClick={(point) => console.log('Clicked on:', point.label)}
    />
  );
};

Getting Started

To get started with TanStack/react-charts, follow these steps:

  1. Install the library using your preferred package manager:
npm install @tanstack/react-charts
  1. Import the necessary components and data accessors from the library:
import { LineChart, BarChart, ScatterChart } from

Competitor Comparisons

23,884

Redefined chart library built with React and D3

Pros of recharts

  • More mature and widely adopted, with a larger community and ecosystem
  • Offers a wider range of chart types and customization options out-of-the-box
  • Better documentation and examples for quick implementation

Cons of recharts

  • Larger bundle size, which may impact performance for complex applications
  • Less flexible for advanced customizations and animations compared to react-charts

Code Comparison

recharts:

import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';

<LineChart width={600} height={300} data={data}>
  <Line type="monotone" dataKey="value" stroke="#8884d8" />
  <CartesianGrid stroke="#ccc" />
  <XAxis dataKey="name" />
  <YAxis />
</LineChart>

react-charts:

import { Chart } from 'react-charts';

<Chart
  options={{
    data,
    primaryAxis: { getValue: datum => datum.name },
    secondaryAxes: [{ getValue: datum => datum.value }],
  }}
/>

Both libraries offer declarative ways to create charts, but recharts provides more built-in components for customization, while react-charts focuses on a more minimal API with greater flexibility for advanced use cases.

64,568

Simple HTML5 Charts using the <canvas> tag

Pros of Chart.js

  • More mature and widely adopted library with extensive documentation
  • Supports a broader range of chart types out-of-the-box
  • Easier to set up and use for simple chart requirements

Cons of Chart.js

  • Less flexible for complex, custom visualizations
  • Not specifically designed for React, requiring additional setup for integration
  • Larger bundle size, which may impact performance for lightweight applications

Code Comparison

Chart.js:

import Chart from 'chart.js/auto';

new Chart(ctx, {
    type: 'bar',
    data: chartData,
    options: chartOptions
});

react-charts:

import { Chart } from 'react-charts';

<Chart
  options={{
    data: chartData,
    primaryAxis: xAxis,
    secondaryAxes: [yAxis]
  }}
/>

react-charts is designed specifically for React applications, offering a more declarative approach to chart creation. It provides better integration with React's component lifecycle and state management. However, it may require more setup for basic charts compared to Chart.js.

Chart.js offers a simpler API for creating charts quickly, but it may require additional work to integrate smoothly with React components and handle dynamic updates efficiently.

Both libraries have their strengths, and the choice between them depends on the specific needs of your project, such as the complexity of visualizations, React integration requirements, and performance considerations.

📊 Interactive JavaScript Charts built on SVG

Pros of ApexCharts

  • Extensive chart types and customization options
  • Built-in responsiveness and animation features
  • Large community and comprehensive documentation

Cons of ApexCharts

  • Larger bundle size due to feature-rich nature
  • Steeper learning curve for advanced customizations
  • Less flexibility for custom chart types

Code Comparison

ApexCharts:

import ApexCharts from 'apexcharts'

const options = {
  chart: { type: 'line' },
  series: [{ data: [30, 40, 35, 50, 49, 60, 70] }],
  xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997] }
}

const chart = new ApexCharts(document.querySelector("#chart"), options)
chart.render()

React Charts:

import { Chart } from 'react-charts'

const data = [
  { date: new Date('1991-01-01'), value: 30 },
  { date: new Date('1992-01-01'), value: 40 },
  // ... more data points
]

const MyChart = () => (
  <Chart
    data={[{ label: 'Series 1', data }]}
    axes={[
      { primary: true, type: 'time', position: 'bottom' },
      { type: 'linear', position: 'left' }
    ]}
  />
)

Both libraries offer powerful charting capabilities, but ApexCharts provides more out-of-the-box features and chart types, while React Charts focuses on simplicity and integration with React ecosystems. The choice between them depends on specific project requirements and developer preferences.

13,142

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

Pros of nivo

  • Offers a wider variety of chart types and customization options
  • Provides server-side rendering capabilities
  • Has built-in theming and responsive design features

Cons of nivo

  • Steeper learning curve due to its extensive API
  • Larger bundle size, which may impact performance for smaller projects

Code Comparison

nivo:

import { ResponsivePie } from '@nivo/pie'

const MyPieChart = ({ data }) => (
  <ResponsivePie
    data={data}
    margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
    innerRadius={0.5}
    padAngle={0.7}
    cornerRadius={3}
  />
)

react-charts:

import { Chart } from 'react-charts'

const MyChart = () => (
  <Chart
    options={{
      data,
      primaryAxis: { type: 'linear' },
      secondaryAxes: [{ type: 'linear' }],
    }}
  />
)

Both libraries offer declarative ways to create charts, but nivo provides more specific components for different chart types, while react-charts uses a more generic approach with configuration options.

10,987

A collection of composable React components for building interactive data visualizations

Pros of Victory

  • More mature and widely adopted library with extensive documentation
  • Supports a broader range of chart types and customization options
  • Offers both React and React Native compatibility

Cons of Victory

  • Larger bundle size due to its comprehensive feature set
  • Steeper learning curve for beginners due to its extensive API
  • Less performant with large datasets compared to React Charts

Code Comparison

Victory:

import { VictoryBar, VictoryChart, VictoryAxis } from 'victory';

<VictoryChart>
  <VictoryAxis tickValues={[1, 2, 3, 4]} />
  <VictoryAxis dependentAxis />
  <VictoryBar data={data} x="quarter" y="earnings" />
</VictoryChart>

React Charts:

import { Chart } from 'react-charts';

<Chart
  options={{
    data,
    primaryAxis: { getValue: datum => datum.quarter },
    secondaryAxes: [{ getValue: datum => datum.earnings }],
  }}
/>

Victory offers a more declarative approach with separate components for each chart element, while React Charts uses a single component with a configuration object. Victory's syntax may be more intuitive for React developers, but React Charts' approach can lead to more concise code for simple charts.

Highcharts JS, the JavaScript charting framework

Pros of Highcharts

  • Extensive library with a wide variety of chart types and customization options
  • Well-established, mature project with robust documentation and community support
  • Works across multiple frameworks and vanilla JavaScript

Cons of Highcharts

  • Commercial license required for most use cases
  • Larger bundle size due to its comprehensive feature set
  • Steeper learning curve for complex customizations

Code Comparison

Highcharts:

Highcharts.chart('container', {
  chart: { type: 'line' },
  series: [{ data: [1, 2, 3, 4, 5] }]
});

React Charts:

import { Chart } from 'react-charts'

function MyChart() {
  return <Chart
    options={{
      data: [{ data: [1, 2, 3, 4, 5] }],
      primaryAxis: { type: 'linear' },
      secondaryAxes: [{ type: 'linear' }]
    }}
  />
}

Summary

Highcharts offers a comprehensive charting solution with extensive options and broad compatibility, but comes with licensing costs and a larger footprint. React Charts provides a more focused, React-specific solution with a simpler API, but may have fewer built-in features. The choice between them depends on project requirements, budget constraints, and the desired level of customization and framework specificity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Charts Header

Simple, immersive and interactive charts for React

#TanStack

Enjoy this library? Try the entire TanStack! React Table, React Query, React Form

Visit react-charts.tanstack.com for docs, guides, API and more!

Quick Features

  • Line Charts
  • Bar Charts
  • Column Charts
  • Bubble Charts
  • Area Charts
  • Axis Stacking
  • Inverted Axes
  • Hyper Responsive
  • Invisibly Powered by D3
  • Declarative
  • Mutliple Axes

Become a Sponsor!

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Tanner Linsley

💻 🤔 💡 🚧 👀

This project follows the all-contributors specification. Contributions of any kind welcome!