Skip to content

Is there a way to render an icon above each bar in BarChart? #492

Closed Answered by ak-spotter
JosephKorel asked this question in Q&A
Discussion options

You must be logged in to vote

Yes @JosephKorel
You can use the topLabelComponent property inside the data array.

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 topLabelComponent property repeatedly, by looping over the array-

const topLabelIcon = () => (
  <View>
    <Icon name="arrow" />
  

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JosephKorel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants