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.

Specific color for specific bar

See original GitHub issue

Hi,

Was just wondering if there is a way to set a color to a bar in a ResponsiveBar chart For example: my keys for bar chart is keys={['2017', '2018', '2019']}

So when I render data just of the key 2017 or 2018 or 2019, I want those bar color to be associated with a single color, as 2019 bar will always show green in color.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

62reactions
plouccommented, Jun 6, 2019

you can use a custom function for the colors property, for example:

const colors = { '2017': 'red', '2018': 'red', '2019': 'green' }
const getColor = bar => colors[bar.id]

const MyBar = () => <Bar colors={getColor} {...otherProps} />
15reactions
fillippeytoncommented, Jul 28, 2020

In case anyone wants to use a color property in the data itself (like the docs), here’s what I’m doing:

const data = [
  {
    id: 'views',
    color: '#00f,
    data: [
      {...},
    ],
  },
  {
    id: 'engagements',
    color: "#f00",
    data: [
      {...},
    ],
  },
];

// render
<ResponsiveLine data={data} colors={d => d.color} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set specific color to some bars in a plotly bar graph?
I'm trying to set different colors for some bars in a plotly express bar graph: import plotly.express as px import pandas as pd...
Read more >
Control the color of barplots built with matplotlib
You can change the color of bars in a barplot using color argument. RGB is a way of making colors. You have to...
Read more >
How to change the color of individual bars in a bar chart?
Here's a simple solution. Notably, all the bar colors are set in a single statement (provided the new colors are pre-defined in a...
Read more >
Vary the colors of same-series data markers in a chart
Vary individual data marker colors manually ... On the Format tab, in the Shape Styles group, click Shape Fill. ... Do one of...
Read more >
How can I choose colors and fill patterns for individual bars in ...
Bars from a particular data set (column) always have the same color and fill pattern. To assign different colors to different bars, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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