question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to change the Bar fill color based on a value in the data set?

See original GitHub issue

I’d like to make the fill color for the column “Current” to be different to the other bars. Would appreciate any help for doing this. Note that the data gets sorted so the order of the bars changes.

Many thanks.

This is what my data looks like.

export default ({coverAmount, rates, current}) => { const data = sortData([ {years: 'Current', premium: parseFloat(current), buffer: 0}, {years: 'R10,000', premium: 10000 * rates[0], buffer: Math.round((10000 * rates[1])/3)}, {years: 'R20,000', premium: 20000 * rates[0], buffer: Math.round((20000 * rates[1])/3) }, {years: 'R30,000', premium: 30000 * rates[0], buffer: Math.round((30000 * rates[1])/3) } ]);

and the Bar statements <Bar stackId="a" dataKey="premium" fill="#005599" /> <Bar stackId="a" dataKey="buffer" fill="#007700" label/>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

30reactions
gplattcommented, Oct 3, 2016

Thank you. This helped me better understand things.

I came across an example using the Cell component and now have it close to what I want with the following code:

<Bar stackId="a" dataKey="premium" >
                {
                  data.map((entry, index) => (
                    <Cell fill={data[index].years === "Current" ? '#290a0a' : '#005599' }/>
                  ))
                }
 </Bar>
     <Bar stackId="a" dataKey="buffer" fill="#007700" label/>
  </BarChart>
14reactions
GGAlanSmitheecommented, May 22, 2018

@gplatt thanks for the example. There is one additional simplification available:

<BarChart>
    <Bar stackId="a" dataKey="premium" >
        {data.map((entry, index) => (
            <Cell fill={entry.years === "Current" ? '#290a0a' : '#005599' }/>
        ))}
    </Bar>
</BarChart>

using entry instead of data[index]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vary the colors of same-series data markers in a chart
Set varying colors of data markers (bars, columns, lines, pie or doughnut slices, dots, and other shapes) automatically in an Office chart.
Read more >
How to color chart bars based on their values - Get Digital Help
(Chart data is made up) This article demonstrates two ways to color chart bars and chart columns based on their values.
Read more >
How to Change Bar Chart Color Based on Category in Excel ...
The article will show you how to change the Bar Chart color based on the category in Excel. The application of this can...
Read more >
Excel: Change the row color based on cell value - Ablebits
Click the "Format…" button and switch to Fill tab to choose the background color. If the default colors do not suffice, click the...
Read more >
Excel Data Bars Conditional Formatting - Contextures
There are two sets of Data Bar options -- Gradient Fill and Solid Fill. ... NOTE: Change the numbers to Bold font, so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found