Is there a way to render an icon above each bar in BarChart? #492
-
Beta Was this translation helpful? Give feedback.
Answered by
ak-spotter
Jan 10, 2024
Replies: 1 comment
-
Yes @JosephKorel Here's an example- const topLabelIcon = () => (
<View>
<Icon name="arrow" />
</View>
);
const data = [
{ value: 20, label: "M", topLabelComponent: topLabelIcon },
{ value: 30, label: "T", topLabelComponent: topLabelIcon },
{ value: 50, label: "W", topLabelComponent: topLabelIcon },
{ value: 40, label: "T", topLabelComponent: topLabelIcon },
{ value: 30, label: "F", topLabelComponent: topLabelIcon },
];
return <BarChart data={data} />; You can avoid writing the const topLabelIcon = () => (
<View>
<Icon name="arrow" />
</View>
);
const data = [
{ value: 20, label: "M"},
{ value: 30, label: "T"},
{ value: 50, label: "W"},
{ value: 40, label: "T"},
{ value: 30, label: "F"},
];
data.forEach(item=>item.topLabelComponent = topLabelIcon);
return <BarChart data={data} />; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JosephKorel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes @JosephKorel
You can use the
topLabelComponent
property inside the data array.Here's an example-
You can avoid writing the
topLabelComponent
property repeatedly, by looping over the array-