Convert Figma logo to code with AI

tomauty logoreact-native-chart

[NOT MAINTAINED] :bar_chart: Add line, area, pie, and bar charts to your React Native app

1,574
238
1,574
59

Top Related Projects

a react native charts wrapper (support android & iOS)

πŸ“ˆ One library to rule all charts for React Native πŸ“Š

victory components for react native

πŸ“ŠReact Native Chart Kit: Line Chart, Bezier Line Chart, Progress Ring, Bar chart, Pie chart, Contribution graph (heatmap)

πŸ“ˆ Beautiful, high-performance Graphs and Charts for React Native built with Skia

Quick Overview

React-Native-Chart is a charting library for React Native applications. It provides a simple and customizable way to create various types of charts, including line charts, bar charts, and pie charts, within React Native projects.

Pros

  • Easy integration with React Native projects
  • Supports multiple chart types (line, bar, pie)
  • Customizable appearance and animations
  • Lightweight and performant

Cons

  • Limited documentation and examples
  • Not actively maintained (last update was several years ago)
  • May have compatibility issues with newer React Native versions
  • Lacks advanced chart features compared to more robust libraries

Code Examples

  1. Creating a simple line chart:
import React from 'react';
import { View } from 'react-native';
import Chart from 'react-native-chart';

const data = [
  [0, 1],
  [1, 3],
  [2, 2],
  [3, 5],
  [4, 4],
];

const LineChartExample = () => (
  <View>
    <Chart
      style={{ width: 300, height: 200 }}
      data={data}
      type="line"
      showDataPoint={true}
      color="#FF0000"
    />
  </View>
);
  1. Creating a bar chart with custom colors:
import React from 'react';
import { View } from 'react-native';
import Chart from 'react-native-chart';

const data = [
  [0, 1],
  [1, 3],
  [2, 2],
  [3, 5],
  [4, 4],
];

const BarChartExample = () => (
  <View>
    <Chart
      style={{ width: 300, height: 200 }}
      data={data}
      type="bar"
      color={['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF']}
    />
  </View>
);
  1. Creating a pie chart with labels:
import React from 'react';
import { View } from 'react-native';
import Chart from 'react-native-chart';

const data = [
  ['A', 30],
  ['B', 20],
  ['C', 50],
];

const PieChartExample = () => (
  <View>
    <Chart
      style={{ width: 300, height: 300 }}
      data={data}
      type="pie"
      showAxis={false}
      showPercentage={true}
    />
  </View>
);

Getting Started

  1. Install the package:

    npm install react-native-chart --save
    
  2. Import and use the Chart component in your React Native app:

    import React from 'react';
    import { View } from 'react-native';
    import Chart from 'react-native-chart';
    
    const MyComponent = () => (
      <View>
        <Chart
          style={{ width: 300, height: 200 }}
          data={[[0, 1], [1, 3], [2, 2], [3, 5], [4, 4]]}
          type="line"
        />
      </View>
    );
    
    export default MyComponent;
    
  3. Customize the chart by adjusting props such as type, color, showDataPoint, etc., according to your requirements.

Competitor Comparisons

a react native charts wrapper (support android & iOS)

Pros of react-native-charts-wrapper

  • More comprehensive and feature-rich charting library
  • Actively maintained with regular updates and bug fixes
  • Supports a wider variety of chart types, including combined charts

Cons of react-native-charts-wrapper

  • Steeper learning curve due to more complex API
  • Larger package size, which may impact app performance
  • Requires additional setup and configuration compared to simpler alternatives

Code Comparison

react-native-charts-wrapper:

<LineChart
  data={{
    dataSets: [{
      values: [{y: 1}, {y: 2}, {y: 3}],
      label: 'Dataset 1',
    }],
  }}
  xAxis={{valueFormatter: ['Jan', 'Feb', 'Mar']}}
/>

react-native-chart:

<LineChart
  data={[1, 2, 3]}
  xLabels={['Jan', 'Feb', 'Mar']}
/>

The code comparison shows that react-native-charts-wrapper requires a more structured data format and offers more customization options, while react-native-chart has a simpler API for basic use cases.

react-native-charts-wrapper is better suited for complex charting needs with extensive customization, while react-native-chart is more appropriate for simpler, straightforward chart implementations in React Native applications.

πŸ“ˆ One library to rule all charts for React Native πŸ“Š

Pros of react-native-svg-charts

  • More actively maintained with recent updates
  • Utilizes SVG for better performance and scalability
  • Offers a wider variety of chart types and customization options

Cons of react-native-svg-charts

  • Steeper learning curve due to more complex API
  • Requires additional dependencies (react-native-svg)
  • May have a larger bundle size due to SVG implementation

Code Comparison

react-native-svg-charts:

import { LineChart } from 'react-native-svg-charts'

<LineChart
    data={[50, 10, 40, 95, 85]}
    svg={{ stroke: 'rgb(134, 65, 244)' }}
    contentInset={{ top: 20, bottom: 20 }}
/>

react-native-chart:

import { LineChart } from 'react-native-chart'

<LineChart
    data={[50, 10, 40, 95, 85]}
    color={'#FF0000'}
    showGrid={false}
/>

react-native-svg-charts offers more flexibility in styling and configuration, while react-native-chart provides a simpler API for basic chart creation. The former uses SVG for rendering, which can lead to better performance and scalability, especially for complex charts or large datasets. However, react-native-chart may be easier to set up and use for simple charting needs.

victory components for react native

Pros of victory-native

  • More comprehensive and feature-rich charting library
  • Better documentation and community support
  • Consistent API across web and mobile platforms

Cons of victory-native

  • Larger package size and potentially higher performance overhead
  • Steeper learning curve due to more complex API

Code Comparison

react-native-chart:

import { LineChart } from 'react-native-chart'

const data = [
  [0, 1], [1, 3], [2, 2], [3, 5], [4, 4]
]

<LineChart data={data} />

victory-native:

import { VictoryChart, VictoryLine } from 'victory-native'

const data = [
  { x: 0, y: 1 }, { x: 1, y: 3 }, { x: 2, y: 2 }, { x: 3, y: 5 }, { x: 4, y: 4 }
]

<VictoryChart>
  <VictoryLine data={data} />
</VictoryChart>

victory-native offers a more flexible and customizable approach, allowing for multiple chart types and styles within a single VictoryChart component. react-native-chart provides a simpler, more straightforward implementation for basic chart types.

πŸ“ŠReact Native Chart Kit: Line Chart, Bezier Line Chart, Progress Ring, Bar chart, Pie chart, Contribution graph (heatmap)

Pros of react-native-chart-kit

  • More chart types available (line, bar, pie, progress ring, etc.)
  • Active development and maintenance
  • Better documentation and examples

Cons of react-native-chart-kit

  • Larger package size
  • Slightly more complex API
  • May have performance issues with large datasets

Code Comparison

react-native-chart:

<Chart
  style={styles.chart}
  data={data}
  verticalGridStep={5}
  type="line"
  showDataPoint={true}
  color={['#e74c3c', '#2980b9', '#2ecc71']}
/>

react-native-chart-kit:

<LineChart
  data={data}
  width={screenWidth}
  height={220}
  chartConfig={{
    backgroundColor: '#e26a00',
    backgroundGradientFrom: '#fb8c00',
    backgroundGradientTo: '#ffa726',
    decimalPlaces: 2,
    color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
    style: {
      borderRadius: 16
    }
  }}
/>

react-native-chart-kit offers more customization options and a wider variety of chart types, but requires more configuration. react-native-chart has a simpler API but fewer features. Both libraries serve their purpose, with react-native-chart-kit being more suitable for complex visualizations and react-native-chart for simpler, performance-critical applications.

πŸ“ˆ Beautiful, high-performance Graphs and Charts for React Native built with Skia

Pros of react-native-graph

  • Better performance due to use of Reanimated 2 and Skia for rendering
  • More modern and actively maintained (last update in 2023)
  • Smoother animations and interactions

Cons of react-native-graph

  • Less customization options compared to react-native-chart
  • Steeper learning curve due to use of Reanimated 2 and Skia
  • Limited chart types (primarily line charts)

Code Comparison

react-native-graph:

import { LineGraph } from 'react-native-graph'

<LineGraph
  points={[{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }]}
  animated={true}
/>

react-native-chart:

import { LineChart } from 'react-native-chart'

<LineChart
  data={[0, 1, 2]}
  style={{ height: 200 }}
  showGrid={false}
  showDataPoint={true}
/>

react-native-graph focuses on performance and smooth animations, leveraging modern libraries like Reanimated 2 and Skia. It's more actively maintained but offers fewer chart types and customization options. react-native-chart provides more chart types and customization but may have lower performance and less smooth animations. The code comparison shows that react-native-graph uses a more structured data format, while react-native-chart has a simpler API for basic usage.

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-native-chart

NOTE: I have not been able to maintain this repo. Recommend switching to Victory Charts.

Screenshot

Getting Started

NPM

  1. npm i react-native-chart --save

Link ART to your project

  1. Right click Libraries and click 'Add Files to {YourProject}'
screen shot 2016-06-17 at 3 39 24 pm
  1. Navigate to your project's node_modules/react-native/Libraries/ART and select 'ART.xcodeproj'
screen shot 2016-06-17 at 3 39 42 pm
  1. Go to Build Phases -> Link Binary With Libraries
screen shot 2016-06-17 at 3 40 00 pm

4 Click the '+', and add libART.a

screen shot 2016-06-17 at 3 40 03 pm

Then rebuild.

Usage

import React, { StyleSheet, View, Component } from 'react-native';
import Chart from 'react-native-chart';

const styles = StyleSheet.create({
	container: {
		flex: 1,
		justifyContent: 'center',
		alignItems: 'center',
		backgroundColor: 'white',
	},
	chart: {
		width: 200,
		height: 200,
	},
});

const data = [[
	[0, 1],
	[1, 3],
	[3, 7],
	[4, 9],
]];

class SimpleChart extends Component {
	render() {
		return (
			<View style={styles.container}>
				<Chart
					style={styles.chart}
					data={data}
					verticalGridStep={5}
					type="line"
					showDataPoint={true}
					color={['#e1cd00']}
				 />
			</View>
		);
	}
}

Properties

Use '' y-values to signify the 'render but empty' data points.

PropertyTypeDescriptionRequiredDefault
dataArray< Array< [number, number] > >An array of arrays of [x, y] pairs.Yes
typestringpie/bar/lineYesbar
colorArray < string >Color of bars/line in line chartNo#4DC4E6
cornerRadiusnumberCorner radius of bars in bar chartNo0
fillColorArray < string >Fill area colors in line chartNo
dataPointColorArray < string >Stroke colors for line chart data pointNo
dataPointFillColorArray < string >Fill colors for line chart data pointNo
dataPointRadiusnumberRadius of the data pointNo3
lineWidthnumberWidth of line chart lineNo1
showDataPointbooleanShow data points on line chartNofalse
sliceColorsArray < string >Array of colors for pie chart slicesYes[ < random colors > ]
axisColorstringColor of axis linesNo#333333
axisLabelColorstringColor of axis testNo#333333
axisLineWidthnumberWidth of axis linesNo1
gridColorstringColor of grid linesNo#333333
gridLineWidthnumberWidth of grid linesNo0.5
hideHorizontalGridLinesbooleanHide grid lines going from LTRNofalse
hideVerticalGridLinesbooleanHide grid lines going up -> downNofalse
showAxisbooleanShow the X and Y axesNotrue
showGridbooleanShow the gridNotrue
showXAxisLabelsbooleanShow X-Axis labelsNotrue
showYAxisLabelsbooleanShow Y-Axis labelsNotrue
styleobjectStyle on the containerNo{}
tightBoundsbooleanTighten min and max bounds strictly to min/max in datasetNofalse
verticalGridStepnumberHow many vertical grid lines to showNo4
horizontalGridStepnumberHow many horizontal grid lines to showNoall
xAxisHeightnumberHeight of X-axis containerNo20
yAxisTransformFunctionTransform data point to y-axis labelNo(_) => _
xAxisTransformFunctionTransform data point to x-axis labelNo(_) => _
yAxisWidthnumberWidth of the Y-axis containerNo30
yAxisUseDecimalbooleanShow decimals on Y-axis labelsNofalse
yAxisShortLabelbooleanShorten yAxis labels with K, M, B for thousand<->billion, etcNofalse

TODO

  • Code cleanup
  • Multi-line chart
  • Horizontal line chart
  • Scatter chart

NPM DownloadsLast 30 Days