2021-08-16 13:41:23 +05:30
|
|
|
import React, {useState} from 'react';
|
|
|
|
import {TouchableOpacity} from 'react-native';
|
|
|
|
import {Alert} from 'react-native';
|
2021-08-12 20:02:44 +05:30
|
|
|
import {View, Text, StyleSheet} from 'react-native';
|
2021-12-02 17:21:19 +05:30
|
|
|
import {BarChart, LineChart} from './src';
|
2021-08-02 00:50:13 +05:30
|
|
|
|
|
|
|
const App = () => {
|
2021-08-16 13:41:23 +05:30
|
|
|
const [toggle, setToggle] = useState(true);
|
|
|
|
|
2021-12-02 17:21:19 +05:30
|
|
|
const [data, setData] = useState([
|
2021-11-26 23:34:22 +05:30
|
|
|
{value: 15, label: 'Jan'},
|
2021-08-12 20:02:44 +05:30
|
|
|
{
|
|
|
|
value: 40,
|
|
|
|
label: 'Feb',
|
|
|
|
verticalLineColor: 'red',
|
2021-08-16 13:41:23 +05:30
|
|
|
// showVerticalLine: true,
|
2021-08-12 20:02:44 +05:30
|
|
|
verticalLineThickness: StyleSheet.hairlineWidth,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 10,
|
|
|
|
label: 'Mar',
|
|
|
|
},
|
2021-08-16 13:41:23 +05:30
|
|
|
{
|
|
|
|
value: 30,
|
|
|
|
label: 'Apr',
|
|
|
|
},
|
|
|
|
{value: 20, label: 'May'},
|
|
|
|
{value: 40, label: 'Jun'},
|
|
|
|
{value: 48, label: 'Jul'},
|
|
|
|
{value: 30, label: 'Aug'},
|
|
|
|
{value: 20, label: 'Sep'},
|
|
|
|
{value: 40, label: 'Oct'},
|
|
|
|
{
|
|
|
|
value: 48,
|
|
|
|
label: 'Nov',
|
|
|
|
onPress: () => Alert.alert('Sales in Nov skyrocketed to $48 M'),
|
|
|
|
},
|
|
|
|
{value: 30, label: 'Dec'},
|
2021-12-02 17:21:19 +05:30
|
|
|
]);
|
2021-08-02 16:41:56 +05:30
|
|
|
|
2021-07-30 18:38:12 +05:30
|
|
|
return (
|
2021-08-12 20:02:44 +05:30
|
|
|
<View
|
|
|
|
style={{
|
2021-11-26 23:34:22 +05:30
|
|
|
marginTop: 100,
|
2021-08-12 20:02:44 +05:30
|
|
|
paddingVertical: 50,
|
|
|
|
}}>
|
2021-12-02 17:21:19 +05:30
|
|
|
{!toggle ? (
|
2021-08-16 13:41:23 +05:30
|
|
|
<BarChart
|
2021-11-26 23:34:22 +05:30
|
|
|
isThreeD
|
|
|
|
key={'xyz'}
|
|
|
|
height={300}
|
|
|
|
maxValue={360}
|
|
|
|
showLine
|
2021-12-02 18:55:03 +05:30
|
|
|
initialSpacing={30}
|
2021-11-26 23:34:22 +05:30
|
|
|
// showVerticalLines
|
|
|
|
lineConfig={{
|
|
|
|
// isAnimated: true,
|
|
|
|
delay: 800,
|
|
|
|
color: 'green',
|
|
|
|
// hideDataPoints: true,
|
|
|
|
// showDataPoint: false,
|
|
|
|
// dataPointsRadius: 5,
|
|
|
|
dataPointsColor: 'purple',
|
|
|
|
dataPointsRadius: 4,
|
|
|
|
thickness: 2,
|
|
|
|
shiftY: 25,
|
|
|
|
curved: true,
|
|
|
|
}}
|
|
|
|
barWidth={32}
|
2021-11-23 21:17:50 +05:30
|
|
|
// width={190}
|
2021-11-26 23:34:22 +05:30
|
|
|
data={[
|
|
|
|
{
|
|
|
|
value: 270,
|
|
|
|
label: 'Jan',
|
|
|
|
},
|
|
|
|
{value: 250, label: 'Feb'},
|
|
|
|
{value: 200, label: 'Mar'},
|
|
|
|
{
|
|
|
|
value: 150,
|
|
|
|
label: 'Apr',
|
|
|
|
showVerticalLine: true,
|
|
|
|
verticalLineColor: 'black',
|
|
|
|
},
|
|
|
|
{value: 200, label: 'May'},
|
|
|
|
{value: 250, label: 'Jun'},
|
|
|
|
{value: 270, label: 'Jul'},
|
|
|
|
]}
|
2021-08-16 13:41:23 +05:30
|
|
|
// horizontal
|
2021-11-26 23:34:22 +05:30
|
|
|
// showReferenceLine1
|
|
|
|
// referenceLine1Position={120}
|
|
|
|
// referenceLine1Config={{
|
|
|
|
// type: 'solid',
|
|
|
|
// color: 'rgba(200,0,0,0.6)',
|
|
|
|
// thickness: 1,
|
|
|
|
// }}
|
|
|
|
// showReferenceLine2
|
|
|
|
// referenceLine2Position={240}
|
|
|
|
// referenceLine2Config={{
|
|
|
|
// type: 'solid',
|
|
|
|
// color: 'rgba(0,0,0,0.6)',
|
|
|
|
// thickness: 1,
|
|
|
|
// }}
|
|
|
|
// showReferenceLine3
|
|
|
|
// referenceLine3Position={330}
|
|
|
|
// referenceLine3Config={{
|
|
|
|
// type: 'solid',
|
|
|
|
// color: 'rgba(0,0,200,0.6)',
|
|
|
|
// thickness: 1,
|
|
|
|
// }}
|
2021-11-23 21:17:50 +05:30
|
|
|
// showYAxisIndices
|
2021-08-16 13:41:23 +05:30
|
|
|
isAnimated
|
|
|
|
showGradient
|
2021-11-26 23:34:22 +05:30
|
|
|
// cappedBars
|
2021-08-16 13:41:23 +05:30
|
|
|
yAxisColor={'rgb(78, 0, 142)'}
|
|
|
|
xAxisColor={'rgb(78, 0, 142)'}
|
|
|
|
xAxisThickness={3}
|
|
|
|
yAxisThickness={3}
|
|
|
|
yAxisTextStyle={{color: 'rgb(78, 0, 142)'}}
|
|
|
|
capColor={'rgb(78, 0, 142)'}
|
|
|
|
capThickness={4}
|
2021-11-26 23:34:22 +05:30
|
|
|
// barWidth={35}
|
|
|
|
frontColor={'rgba(200, 100, 244,0.2)'}
|
|
|
|
gradientColor={'rgba(78, 0, 142,1)'}
|
|
|
|
// rulesType="dashed"
|
|
|
|
// rulesColor={'rgba(0,200,0,0.5)'}
|
|
|
|
// rulesThickness={1}
|
|
|
|
// dashWidth={12}
|
|
|
|
// dashGap={2}
|
2021-08-16 13:41:23 +05:30
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<LineChart
|
2021-11-23 21:17:50 +05:30
|
|
|
// width={150}
|
2021-12-02 17:21:19 +05:30
|
|
|
// hideDataPoints1
|
|
|
|
// spacing={30}
|
2021-08-16 13:41:23 +05:30
|
|
|
data={data}
|
2021-12-02 17:21:19 +05:30
|
|
|
// data2={lineData1}
|
|
|
|
areaChart
|
2021-12-02 18:55:03 +05:30
|
|
|
initialSpacing={20}
|
2021-12-02 19:26:44 +05:30
|
|
|
// customDataPoint={() => {
|
|
|
|
// return (
|
|
|
|
// <View
|
|
|
|
// style={{
|
|
|
|
// height: 10,
|
|
|
|
// width: 10,
|
|
|
|
// backgroundColor: 'red',
|
|
|
|
// borderWidth: 2,
|
|
|
|
// borderColor: 'blue',
|
|
|
|
// borderRadius: 5,
|
|
|
|
// }}
|
|
|
|
// />
|
|
|
|
// );
|
|
|
|
// }}
|
|
|
|
// focusedCustomDataPoint={() => {
|
|
|
|
// return (
|
|
|
|
// <View
|
|
|
|
// style={{
|
|
|
|
// height: 14,
|
|
|
|
// width: 14,
|
|
|
|
// backgroundColor: 'green',
|
|
|
|
// borderWidth: 2,
|
|
|
|
// borderColor: 'yellow',
|
|
|
|
// borderRadius: 7,
|
|
|
|
// }}
|
|
|
|
// />
|
|
|
|
// );
|
|
|
|
// }}
|
|
|
|
// onPress={(item, index) => {
|
|
|
|
// console.log('index-->', index);
|
|
|
|
// setData(data => {
|
|
|
|
// item.focusedCustomDataPoint = () => {
|
|
|
|
// return (
|
|
|
|
// <View
|
|
|
|
// style={{
|
|
|
|
// height: 14,
|
|
|
|
// width: 14,
|
|
|
|
// backgroundColor: 'green',
|
|
|
|
// borderWidth: 2,
|
|
|
|
// borderColor: 'yellow',
|
|
|
|
// borderRadius: 7,
|
|
|
|
// }}
|
|
|
|
// />
|
|
|
|
// );
|
|
|
|
// };
|
|
|
|
// data[index] = item;
|
|
|
|
// console.log('data------.....', data);
|
|
|
|
// return data;
|
|
|
|
// });
|
|
|
|
// }}
|
2021-12-02 17:21:19 +05:30
|
|
|
// disableScroll
|
|
|
|
pressEnabled
|
|
|
|
// showDataPointOnPress
|
|
|
|
showStripOnPress
|
|
|
|
showTextOnPress
|
|
|
|
textShiftY={-10}
|
|
|
|
textShiftX={-5}
|
|
|
|
textFontSize={18}
|
|
|
|
textColor={'green'}
|
|
|
|
stripWidth={1}
|
|
|
|
// stripHeight={200}
|
2021-12-02 18:55:03 +05:30
|
|
|
// stripHeight={200}
|
|
|
|
stripOpacity={1}
|
2021-08-16 13:41:23 +05:30
|
|
|
curved
|
|
|
|
isAnimated
|
2021-12-02 17:21:19 +05:30
|
|
|
animationDuration={2000}
|
|
|
|
// animationDuration={2000}
|
|
|
|
// dataPointsShape="rectangular"
|
|
|
|
// showGradient
|
2021-08-16 13:41:23 +05:30
|
|
|
color={'rgb(78, 0, 142)'}
|
|
|
|
yAxisColor={'rgb(78, 0, 142)'}
|
|
|
|
xAxisColor={'rgb(78, 0, 142)'}
|
2021-12-02 18:55:03 +05:30
|
|
|
// dataPointsColor={'yellow'}
|
|
|
|
dataPointsWidth={22}
|
|
|
|
dataPointsHeight={22}
|
2021-08-16 13:41:23 +05:30
|
|
|
xAxisThickness={3}
|
|
|
|
yAxisThickness={3}
|
2021-12-02 17:21:19 +05:30
|
|
|
dataPointsRadius={4}
|
2021-12-02 19:26:44 +05:30
|
|
|
focusedDataPointRadius={10}
|
2021-08-16 13:41:23 +05:30
|
|
|
yAxisTextStyle={{color: 'rgb(78, 0, 142)'}}
|
|
|
|
startFillColor={'rgb(200, 100, 244)'}
|
|
|
|
startOpacity={0.9}
|
|
|
|
endFillColor={'rgb(255, 255, 255)'}
|
|
|
|
endOpacity={0.2}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => setToggle(!toggle)}
|
|
|
|
style={{marginTop: 100, alignSelf: 'center'}}>
|
|
|
|
<Text>Line Chart</Text>
|
|
|
|
</TouchableOpacity>
|
2021-07-30 18:38:12 +05:30
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|