Hello guys, From past few days we have been posting various types of Charts tutorial in our website. Today we would also learn about another Chart tutorial known as Rounded Progress Chart. We would use react-native-chart-kit NPM package in our tutorial to make Progress Chart. So in this tutorial we would learn about How to Create Rounded Circular Progress Chart in React Native Android iOS Example.
Contents in this project Create Rounded Circular Progress Chart in React Native Android iOS Example :-
1. First of all we’ve to install react-native-chart-kit and its supporting react-native-svg NPM package in our project. So open your project’s Root location in Command Prompt or Terminal and execute below commands.
1
|
npm install react–native–chart–kit —save
|
1
|
npm install react–native–svg —save
|
2. Friends, 2nd step is only for iOS users only. We have to install the PODS to link the library to the project. So execute below command in MAC only for iOS project.
1
|
cd ios && pod install && cd ..
|
3. Now we can start coding for the app. Open your project’s main App.js file and import View, StyleSheet, Text and Dimensions component.
1
2
3
|
import React from ‘react’;
import { View, StyleSheet, Text, Dimensions } from ‘react-native’;
|
4. Importing ProgressChart from “react-native-chart-kit” package.
1
|
import { ProgressChart } from “react-native-chart-kit”;
|
5. Creating a Constant variable named as screenWidth and here with the help of Dimensions API we would calculate the Width of Screen.
1
|
const screenWidth = Dimensions.get(“window”).width;
|
6. Creating our main Export default App component.
1
2
3
4
5
|
export default function App() {
}
|
7. Creating a constant named as data. In this constant we would define the Chart labels and chart values.
1
2
3
4
|
const data = {
labels: [“Apple”, “Banana”, “Cherry”], // optional
data: [0.2, 0.5, 0.8]
};
|
8. Crating return() block, Now we would make the ProgressChart component here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
return (
<View style={styleSheet.MainContainer}>
<ProgressChart
data={data}
width={ screenWidth – 15 }
height={220}
chartConfig={{
//backgroundColor: ‘#478438’,
backgroundGradientFrom: ‘#FFF8E1’,
backgroundGradientTo: ‘#FFF8E1’,
//decimalPlaces: 2,
color: (opacity = 1) => `rgba(255, 0, 0, ${opacity})`,
}}
style= {{
borderRadius: 15,
}}
/>
<Text style={{ fontSize: 28, textAlign: ‘center’ }}> Progress Chart in React Native </Text>
</View>
);
|
9. Creating Style.
1
2
3
4
5
6
7
8
9
|
const styleSheet = StyleSheet.create({
MainContainer: {
flex: 1,
alignItems: ‘center’,
justifyContent: ‘center’
}
});
|
10. Complete Source Code for App.js file :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import React from ‘react’;
import { View, StyleSheet, Text, Dimensions } from ‘react-native’;
import { ProgressChart } from “react-native-chart-kit”;
const screenWidth = Dimensions.get(“window”).width;
export default function App() {
const data = {
labels: [“Apple”, “Banana”, “Cherry”], // optional
data: [0.2, 0.5, 0.8]
};
return (
<View style={styleSheet.MainContainer}>
<ProgressChart
data={data}
width={ screenWidth – 15 }
height={220}
chartConfig={{
//backgroundColor: ‘#478438’,
backgroundGradientFrom: ‘#FFF8E1’,
backgroundGradientTo: ‘#FFF8E1’,
//decimalPlaces: 2,
color: (opacity = 1) => `rgba(255, 0, 0, ${opacity})`,
}}
style= {{
borderRadius: 15,
}}
/>
<Text style={{ fontSize: 28, textAlign: ‘center’ }}> Progress Chart in React Native </Text>
</View>
);
}
const styleSheet = StyleSheet.create({
MainContainer: {
flex: 1,
alignItems: ‘center’,
justifyContent: ‘center’
}
});
|
Screenshot :-