Here's a snapshot of my code:
const data = filteredKeys.map((key, index) => {
return {
key,
value: filteredValues[index],
svg: { fill: colors[index] },
arc: {
outerRadius: 70 + filteredValues[index] + '%',
padAngle: label === key ? 0.1 : 0,
},
onPress: () =>
setSelectedSlice({ label: key, value: filteredValues[index] }),
};
});
const Labels = ({ slices, height, width }) => {
return slices.map((slice, index) => {
console.log(slice);
const { labelCentroid, pieCentroid, data } = slice;
return (
<Text
key={index}
x={labelCentroid[0]}
y={labelCentroid[1]}
fill={'#000'}
textAnchor={'middle'}
alignmentBaseline={'center'}
fontSize={14}
stroke={'black'}
strokeWidth={0.2}
>
{data.key}
</Text>
);
});
};
return (
<View style={styles.container}>
<PieChart
style={{ height: 300 }}
outerRadius={'100%'}
innerRadius={'10%'}
data={data}
labelRadius={'85%'}
>
<Labels />
</PieChart>
</View>
);
This is the result:
I want to labels to align like this:
The labels look very inconsistent on different pie charts, that's why I want to render the labels along the curve of their respective arcs (center of the arc is prefered).
I have tried TextPath and TSpan from react-native-svg, but couldn't figure out how to draw the TextPath when it is child of the component along which the path is to be drawn.