react-native-chart
[NOT MAINTAINED] :bar_chart: Add line, area, pie, and bar charts to your React Native app
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
- 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>
);
- 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>
);
- 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
-
Install the package:
npm install react-native-chart --save
-
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;
-
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 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-native-chart
NOTE: I have not been able to maintain this repo. Recommend switching to Victory Charts.
Getting Started
npm i react-native-chart --save
Link ART to your project
- Right click Libraries and click 'Add Files to {YourProject}'
- Navigate to your project's node_modules/react-native/Libraries/ART and select 'ART.xcodeproj'
- Go to Build Phases -> Link Binary With Libraries
4 Click the '+', and add libART.a
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.
Property | Type | Description | Required | Default |
---|---|---|---|---|
data | Array< Array< [number, number] > > | An array of arrays of [x, y] pairs. | Yes | |
type | string | pie/bar/line | Yes | bar |
color | Array < string > | Color of bars/line in line chart | No | #4DC4E6 |
cornerRadius | number | Corner radius of bars in bar chart | No | 0 |
fillColor | Array < string > | Fill area colors in line chart | No | |
dataPointColor | Array < string > | Stroke colors for line chart data point | No | |
dataPointFillColor | Array < string > | Fill colors for line chart data point | No | |
dataPointRadius | number | Radius of the data point | No | 3 |
lineWidth | number | Width of line chart line | No | 1 |
showDataPoint | boolean | Show data points on line chart | No | false |
sliceColors | Array < string > | Array of colors for pie chart slices | Yes | [ < random colors > ] |
axisColor | string | Color of axis lines | No | #333333 |
axisLabelColor | string | Color of axis test | No | #333333 |
axisLineWidth | number | Width of axis lines | No | 1 |
gridColor | string | Color of grid lines | No | #333333 |
gridLineWidth | number | Width of grid lines | No | 0.5 |
hideHorizontalGridLines | boolean | Hide grid lines going from LTR | No | false |
hideVerticalGridLines | boolean | Hide grid lines going up -> down | No | false |
showAxis | boolean | Show the X and Y axes | No | true |
showGrid | boolean | Show the grid | No | true |
showXAxisLabels | boolean | Show X-Axis labels | No | true |
showYAxisLabels | boolean | Show Y-Axis labels | No | true |
style | object | Style on the container | No | {} |
tightBounds | boolean | Tighten min and max bounds strictly to min/max in dataset | No | false |
verticalGridStep | number | How many vertical grid lines to show | No | 4 |
horizontalGridStep | number | How many horizontal grid lines to show | No | all |
xAxisHeight | number | Height of X-axis container | No | 20 |
yAxisTransform | Function | Transform data point to y-axis label | No | (_) => _ |
xAxisTransform | Function | Transform data point to x-axis label | No | (_) => _ |
yAxisWidth | number | Width of the Y-axis container | No | 30 |
yAxisUseDecimal | boolean | Show decimals on Y-axis labels | No | false |
yAxisShortLabel | boolean | Shorten yAxis labels with K, M, B for thousand<->billion, etc | No | false |
TODO
- Code cleanup
- Multi-line chart
- Horizontal line chart
- Scatter chart
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
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