react-native-graph
π Beautiful, high-performance Graphs and Charts for React Native built with Skia
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)
[NOT MAINTAINED] :bar_chart: Add line, area, pie, and bar charts to your React Native app
Quick Overview
React Native Graph is a high-performance, customizable graph library for React Native applications. It provides smooth animations and interactions, making it ideal for creating visually appealing and responsive charts in mobile apps.
Pros
- High performance with 60 FPS animations
- Customizable appearance and behavior
- Supports both iOS and Android platforms
- Written in TypeScript for better type safety and developer experience
Cons
- Limited to line graphs and bar charts
- Requires some setup and configuration
- Documentation could be more comprehensive
- May have a learning curve for developers new to React Native
Code Examples
- Basic Line Graph:
import { LineGraph } from 'react-native-graph'
const MyGraph = () => (
<LineGraph
points={[
{ x: 0, y: 5 },
{ x: 1, y: 8 },
{ x: 2, y: 3 },
{ x: 3, y: 10 }
]}
color="blue"
/>
)
- Customized Line Graph with Gradient:
import { LineGraph } from 'react-native-graph'
const CustomGraph = () => (
<LineGraph
points={[
{ x: 0, y: 5 },
{ x: 1, y: 8 },
{ x: 2, y: 3 },
{ x: 3, y: 10 }
]}
color="purple"
gradientFillColors={['rgba(100, 0, 255, 0.5)', 'rgba(100, 0, 255, 0)']}
lineThickness={3}
animated={true}
/>
)
- Interactive Graph with Tooltip:
import { LineGraph } from 'react-native-graph'
const InteractiveGraph = () => (
<LineGraph
points={[
{ x: 0, y: 5 },
{ x: 1, y: 8 },
{ x: 2, y: 3 },
{ x: 3, y: 10 }
]}
color="green"
enablePanGesture={true}
onPointSelected={(point) => console.log('Selected point:', point)}
SelectionDot={({ x, y }) => (
<View style={{ position: 'absolute', left: x - 5, top: y - 5, width: 10, height: 10, borderRadius: 5, backgroundColor: 'green' }} />
)}
/>
)
Getting Started
-
Install the package:
npm install react-native-graph
-
Import and use the component in your React Native app:
import { LineGraph } from 'react-native-graph' const App = () => ( <LineGraph points={[ { x: 0, y: 5 }, { x: 1, y: 8 }, { x: 2, y: 3 }, { x: 3, y: 10 } ]} color="red" /> )
-
Customize the graph as needed using available props and options.
Competitor Comparisons
a react native charts wrapper (support android & iOS)
Pros of react-native-charts-wrapper
- Offers a wider variety of chart types, including pie charts, radar charts, and bubble charts
- Provides more customization options for chart appearance and behavior
- Has a larger community and longer development history, potentially leading to better stability and support
Cons of react-native-charts-wrapper
- Relies on native dependencies, which can complicate the build process and increase app size
- May have performance issues with large datasets due to its use of native components
- Less focused on modern React Native practices and may not integrate as smoothly with newer codebases
Code Comparison
react-native-charts-wrapper:
<LineChart
data={{
datasets: [{
data: [45, 80, 100, 70, 90]
}]
}}
width={Dimensions.get("window").width}
height={220}
/>
react-native-graph:
<LineGraph
points={[
{ x: 0, y: 45 },
{ x: 1, y: 80 },
{ x: 2, y: 100 },
{ x: 3, y: 70 },
{ x: 4, y: 90 }
]}
/>
The code comparison shows that react-native-graph uses a more straightforward data structure for points, while react-native-charts-wrapper uses a nested data object. react-native-graph's approach may be more intuitive for simple use cases, but react-native-charts-wrapper's structure allows for more complex data representations.
π One library to rule all charts for React Native π
Pros of react-native-svg-charts
- More comprehensive set of chart types (line, bar, pie, etc.)
- Longer development history and larger community
- Extensive documentation and examples
Cons of react-native-svg-charts
- Less performant for large datasets
- Not optimized for real-time updates
- Limited customization options for complex visualizations
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-graph:
import { LineGraph } from 'react-native-graph'
<LineGraph
points={[{ x: 0, y: 50 }, { x: 1, y: 10 }, { x: 2, y: 40 }, { x: 3, y: 95 }, { x: 4, y: 85 }]}
color="rgb(134, 65, 244)"
/>
react-native-graph focuses on high-performance line graphs with smooth animations, while react-native-svg-charts offers a wider variety of chart types. react-native-graph is more suitable for real-time data visualization and large datasets, whereas react-native-svg-charts provides more options for static charts and simpler implementations. The code comparison shows that react-native-graph requires more explicit data formatting, while react-native-svg-charts has a more straightforward API for basic use cases.
victory components for react native
Pros of victory-native
- More comprehensive charting library with a wider variety of chart types
- Part of a larger ecosystem (Victory) with consistent API across web and mobile
- Highly customizable with extensive documentation
Cons of victory-native
- Larger bundle size and potentially slower performance
- Steeper learning curve due to more complex API
- Less focused on specific React Native optimizations
Code Comparison
react-native-graph:
<Graph
points={data}
color="#ff0000"
animated={true}
style={{ height: 200, width: '100%' }}
/>
victory-native:
<VictoryChart>
<VictoryLine
data={data}
style={{ data: { stroke: "#ff0000" } }}
animate={{ duration: 2000 }}
/>
</VictoryChart>
Summary
react-native-graph is a lightweight, performance-focused library specifically for line graphs in React Native. It offers a simpler API and potentially better performance for basic line charts.
victory-native is a more comprehensive charting library that provides a wide range of chart types and customization options. It's part of the larger Victory ecosystem, offering consistency across platforms but at the cost of a larger bundle size and potentially more complex implementation.
Choose react-native-graph for simple, performant line charts in React Native, or victory-native for more diverse and customizable charting needs across platforms.
πReact Native Chart Kit: Line Chart, Bezier Line Chart, Progress Ring, Bar chart, Pie chart, Contribution graph (heatmap)
Pros of react-native-chart-kit
- Offers a wider variety of chart types, including pie charts, progress rings, and contribution graphs
- Provides more customization options for chart appearance and styling
- Has a larger community and more frequent updates
Cons of react-native-chart-kit
- Performance may be slower for large datasets or complex charts
- Less focus on smooth animations and interactions compared to react-native-graph
- Requires more setup and configuration for advanced use cases
Code Comparison
react-native-chart-kit:
import { LineChart } from 'react-native-chart-kit';
<LineChart
data={{
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{ data: [20, 45, 28, 80, 99, 43] }],
}}
width={Dimensions.get('window').width}
height={220}
chartConfig={{
backgroundColor: '#e26a00',
backgroundGradientFrom: '#fb8c00',
backgroundGradientTo: '#ffa726',
decimalPlaces: 2,
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`,
style: { borderRadius: 16 },
}}
/>
react-native-graph:
import { LineGraph } from 'react-native-graph';
<LineGraph
points={[
{ x: 0, y: 20 },
{ x: 1, y: 45 },
{ x: 2, y: 28 },
{ x: 3, y: 80 },
{ x: 4, y: 99 },
{ x: 5, y: 43 },
]}
animated={true}
color="#ff0000"
/>
[NOT MAINTAINED] :bar_chart: Add line, area, pie, and bar charts to your React Native app
Pros of react-native-chart
- More comprehensive charting library with multiple chart types (line, bar, pie, etc.)
- Longer development history and larger community support
- More customization options and flexibility in chart styling
Cons of react-native-chart
- Heavier package size due to more features
- May have a steeper learning curve for simple use cases
- Less focus on performance optimization compared to react-native-graph
Code Comparison
react-native-chart:
import { LineChart } from 'react-native-chart-kit';
<LineChart
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [{
data: [20, 45, 28, 80, 99, 43]
}]
}}
width={Dimensions.get('window').width}
height={220}
/>
react-native-graph:
import { LineGraph } from 'react-native-graph';
<LineGraph
points={[
{ x: 0, y: 20 },
{ x: 1, y: 45 },
{ x: 2, y: 28 },
{ x: 3, y: 80 },
{ x: 4, y: 99 },
{ x: 5, y: 43 }
]}
/>
react-native-graph focuses on simplicity and performance for line graphs, while react-native-chart offers a wider range of chart types and customization options. The choice between the two depends on the specific project requirements, performance needs, and desired chart complexity.
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-graph
Beautiful, high-performance Graphs/Charts for React Native.
About
react-native-graph is a Line Graph implementation based on the high performance 2D graphics rendering engine "Skia". It's used in the Pink Panda Wallet app to power thousands of token graphs every day.
- Γ°ΒΒΒΓ―ΒΈΒ Faster and smoother than react-native-svg graphs
- Γ’Β‘︠Native path interpolation in Skia
- Γ°ΒΒΒ Up to 120 FPS animations
- Γ°ΒΒΒ Cubic bezier rendering for smoother edges
- Γ°ΒΒΒ Smooth pan/scrubbing gesture
- Γ°ΒΒΒ° Made for crypto apps and Wallets
- Γ’ΒΒ Does not block navigation, press or scroll animations
Installation
yarn add react-native-reanimated yarn add react-native-gesture-handler yarn add @shopify/react-native-skia yarn add react-native-graph
Usage
function App() {
const priceHistory = usePriceHistory('ethereum')
return <LineGraph points={priceHistory} color="#4484B2" />
}
Configuration
animated
Whether to animate between data changes.
Animations are ran using the Skia animation system and are fully natively interpolated to ensure best possible performance.
If animated
is false
, a light-weight implementation of the graph renderer will be used, which is optimal for displaying a lot of graphs in large lists.
Example:
<LineGraph
points={priceHistory}
animated={true}
color="#4484B2"
/>
enablePanGesture
Whether to enable the pan gesture.
Requires
animated
to betrue
.
There are three events fired when the user interacts with the graph:
onGestureStart
: Fired once the user presses and holds down on the graph. The pan gesture activates.onPointSelected
: Fired for each point the user pans through. You can use this event to update labels or highlight selection in the graph.onGestureEnd
: Fired once the user releases his finger and the pan gesture deactivates.
The pan gesture can be configured using these props:
panGestureDelay
: Set delay for the pan gesture to activate. Set to0
to start immediately after touch. Defaults to300
.
Example:
<LineGraph
points={priceHistory}
animated={true}
color="#4484B2"
enablePanGesture={true}
onGestureStart={() => hapticFeedback('impactLight')}
onPointSelected={(p) => updatePriceTitle(p)}
onGestureEnd={() => resetPriceTitle()}
/>
TopAxisLabel
/ BottomAxisLabel
Used to render labels above or below the Graph.
Requires
animated
to betrue
.
Usually this is used to render the maximum and minimum values of the Graph. You can get the maximum and minimum values from your graph points array, and smoothly animate the labels on the X axis accordingly.
Example:
<LineGraph
points={priceHistory}
animated={true}
color="#4484B2"
TopAxisLabel={() => <AxisLabel x={max.x} value={max.value} />}
BottomAxisLabel={() => <AxisLabel x={min.x} value={min.value} />}
/>
Range
Used to define a range for the graph canvas
This range has to be bigger than the span of the provided data points. This feature can be used, e.g. if the graph should show a fixed timeframe, whether there's data for that period or not.
This example shows data in the timeframe between 01/01/2000 to 01/31/2000 and caps the value between 0 and 200:
<LineGraph
points={priceHistory}
animated={true}
color="#4484B2"
enablePanGesture={true}
range={{
x: {
min: new Date(new Date(2000, 1, 1).getTime()),
max: new Date(
new Date(2000, 1, 1).getTime() +
31 * 1000 * 60 * 60 * 24
)
},
y: {
min: 0,
max: 200
}
}}
/>
SelectionDot
Used to render the selection dot.
Requires
animated
andenablePanGesture
to betrue
.
If SelectionDot
is missing or undefined
, a default one is provided with an outer ring and light shadow.
Example:
<LineGraph
points={priceHistory}
animated={true}
color="#4484B2"
enablePanGesture={true}
SelectionDot={CustomSelectionDot}
/>
See this example <SelectionDot />
component.
Sponsor
react-native-graph is sponsored by Pink Panda.
Download the Pink Panda mobile app to see react-native-graph in action!
Community Discord
Join the Margelo Community Discord to chat about react-native-graph or other Margelo libraries.
Adopting at scale
react-native-graph was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at hello@margelo.io!
Thanks
Special thanks to William Candillon and Christian Falch for their amazing help and support for React Native Skia Γ’Β€ï¸Β
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)
[NOT MAINTAINED] :bar_chart: Add line, area, pie, and bar charts to your React Native app
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