378 lines
9.7 KiB
JavaScript
Raw Normal View History

import React, {useState} from 'react';
import {TouchableOpacity} from 'react-native';
import {Alert} from 'react-native';
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 = () => {
const [toggle, setToggle] = useState(true);
const dPoint = () => {
return (
<View
style={{
width: 20,
height: 20,
backgroundColor: 'white',
borderWidth: 4,
borderRadius: 10,
borderColor: '#07BAD1',
}}
/>
);
};
const lcomp = val => {
return (
<View style={{width: 70, marginLeft: 7}}>
<Text style={{color: 'white', fontWeight: 'bold'}}>{val}</Text>
</View>
);
};
const latestData = [
{
value: 100,
labelComponent: () => lcomp('22 Nov'),
customDataPoint: dPoint,
},
{
value: 140,
hideDataPoint: true,
},
{
value: 250,
customDataPoint: dPoint,
},
{
value: 290,
hideDataPoint: true,
},
{
value: 410,
labelComponent: () => lcomp('24 Nov'),
customDataPoint: dPoint,
showStrip: true,
stripHeight: 190,
stripColor: 'black',
dataPointLabelComponent: () => {
return (
<View
style={{
backgroundColor: 'black',
paddingHorizontal: 8,
paddingVertical: 5,
borderRadius: 4,
}}>
<Text style={{color: 'white'}}>410</Text>
</View>
);
},
dataPointLabelShiftY: -70,
dataPointLabelShiftX: -14,
},
{
value: 440,
hideDataPoint: true,
},
{
value: 300,
customDataPoint: dPoint,
},
{
value: 280,
hideDataPoint: true,
},
{
value: 180,
labelComponent: () => lcomp('26 Nov'),
customDataPoint: dPoint,
},
{
value: 150,
hideDataPoint: true,
},
{
value: 150,
customDataPoint: dPoint,
},
];
const customLabel = val => {
return (
<View
style={{
backgroundColor: 'black',
// padding: 16,
borderRadius: 8,
width: 30,
paddingVertical: 4,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text style={{color: 'white'}}>{val}</Text>
</View>
);
};
2021-12-02 17:21:19 +05:30
const [data, setData] = useState([
{value: 15, label: 'Jan'},
{
value: 40,
label: 'Feb',
verticalLineColor: 'red',
// showVerticalLine: true,
verticalLineThickness: StyleSheet.hairlineWidth,
dataPointLabelComponent: () => customLabel(40),
},
{
value: 10,
label: 'Mar',
dataPointLabelComponent: () => customLabel(10),
},
{
value: 30,
label: 'Apr',
dataPointLabelComponent: () => customLabel(30),
},
{
value: 20,
label: 'May',
dataPointLabelComponent: () => customLabel(20),
},
{
value: 40,
label: 'Jun',
focusedDataPointLabelComponent: () => customLabel(40),
},
{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 (
<View
style={{
marginTop: 100,
paddingVertical: 50,
backgroundColor: '#414141',
}}>
<LineChart
thickness={6}
color="#07BAD1"
maxValue={600}
noOfSections={3}
areaChart
yAxisTextStyle={{color: 'lightgray'}}
data={latestData}
curved
startFillColor={'rgb(84,219,234)'}
endFillColor={'rgb(84,219,234)'}
startOpacity={0.4}
endOpacity={0.4}
spacing={38}
backgroundColor="#414141"
rulesColor="gray"
rulesType="solid"
initialSpacing={10}
yAxisColor="lightgray"
xAxisColor="lightgray"
dataPointsHeight={20}
dataPointsWidth={20}
/>
{/* {!toggle ? (
<BarChart
isThreeD
key={'xyz'}
height={300}
maxValue={360}
showLine
initialSpacing={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}
// width={190}
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'},
]}
// horizontal
// 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,
// }}
// showYAxisIndices
isAnimated
showGradient
// cappedBars
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}
// 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}
/>
) : (
<LineChart
// width={150}
2021-12-02 17:21:19 +05:30
// hideDataPoints1
// spacing={30}
data={data}
dataPointLabelWidth={30}
dataPointLabelShiftY={-30}
2021-12-02 17:21:19 +05:30
// data2={lineData1}
areaChart
initialSpacing={20}
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}
2021-12-02 17:21:19 +05:30
// stripHeight={200}
// stripHeight={200}
// stripOpacity={1}
// curved
// isAnimated
// animationDuration={2000}
2021-12-02 17:21:19 +05:30
// animationDuration={2000}
// dataPointsShape="rectangular"
// showGradient
color={'rgb(78, 0, 142)'}
yAxisColor={'rgb(78, 0, 142)'}
xAxisColor={'rgb(78, 0, 142)'}
// dataPointsColor={'yellow'}
dataPointsWidth={20}
dataPointsHeight={20}
xAxisThickness={3}
yAxisThickness={3}
// dataPointsRadius={4}
// focusedDataPointRadius={10}
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;