import React from 'react';
import {ScrollView} from 'react-native';
import {View, PieChart, Card, Text, Badge, PieChartSegmentProps, Colors} from 'react-native-ui-lib';
const SEGMENTS: PieChartSegmentProps[] = [
{
percentage: 40,
color: Colors.blue30
},
{
percentage: 30,
color: Colors.red30
},
{
percentage: 20,
color: Colors.green30
},
{
percentage: 10,
color: Colors.purple30
}
];
const MONOCHROME_SEGMENTS: PieChartSegmentProps[] = [
{
percentage: 40,
color: Colors.blue70
},
{
percentage: 30,
color: Colors.blue50
},
{
percentage: 20,
color: Colors.blue30
},
{
percentage: 10,
color: Colors.blue10
}
];
const NOT_FULL_PIECHART: PieChartSegmentProps[] = [
{
percentage: 30,
color: Colors.blue30
},
{
percentage: 40,
color: Colors.red30
}
];
const PieChartScreen = () => {
const renderSegmentLabel = (segment: PieChartSegmentProps, text: string) => {
const {percentage, color} = segment;
return (
{text}
{percentage}%
);
};
const renderPieChartCard = (segments: PieChartSegmentProps[]) => {
return (
{segments.map((segment, index) => renderSegmentLabel(segment, `Value ${index + 1}`))}
);
};
return (
PieChart
{renderPieChartCard(SEGMENTS)}
Monochrome colors
{renderPieChartCard(MONOCHROME_SEGMENTS)}
Not Full PieChart
{renderPieChartCard(NOT_FULL_PIECHART)}
);
};
export default PieChartScreen;