Skip to content

Dynamic fill Color for Bar with Positive Negative Referenced Chart #4278

Answered by ckifer
jiaulislam asked this question in Q&A
Discussion options

You must be logged in to vote

you can use the Cell component within Bar to change the color based off of your data.

Similar to this example except without the custom Bar
https://recharts.org/en-US/examples/CustomShapeBarChart

      <Bar dataKey={option.valueKey}>
        {data.map((entry, index) => (
          <Cell key={`cell-${index}`} fill={entry[option.valueKey] < 0 ? 'red' : 'green'} />
        ))}
      </Bar>

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Yyana22
Comment options

@Yyana22
Comment options

@Yyana22
Comment options

@ckifer
Comment options

@ckifer
Comment options

Answer selected by ckifer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants