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.

Simple way to color bar chart

See original GitHub issue

Hi. I’m trying to color a stacked bar chart, and I’ve looked at some other complicated solutions, but I need something simple!

I am trying this which seems to be a hotch-potch of code. I’ve tried the selectAll with about every combination: rect.bar, rect.stack, g.rect.bar etc.

.renderlet(function(chart){
       chart.selectAll("g.rect.stack").attr("fill", function(d){
            if(d.key == "a) Free")   
         return "green-bar";
    else if(d.key == "b) Partly Free")
         return "yellow-bar";
     else if(d.key == "c) Not Free")
         return "red-bar"; 
        });})

Anyone help me get over this?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
nitinsuranacommented, Jun 24, 2016

Here’s the solution for clicking on a bar not dimming the other unselected stackedbars.

chart.selectAll("g rect").style("fill", function (d) {
                        return colorMap[d.layer];
                    });
                    chart.selectAll('g.dc-legend-item rect').style('fill', function (d) {
                        return colorMap[d.name];
                    });
                    chart.selectAll("g rect.deselected").style("fill", function (d) {
                        return '#ccc';
                    });
1reaction
NickQiZhucommented, Jun 17, 2013

The renderlet solution should work however you need to set the fill to color instead of css class:

.renderlet(function(chart){
       chart.selectAll("g.rect.stack").attr("fill", function(d){
            if(d.key == "a) Free")   
         return "green";
    else if(d.key == "b) Partly Free")
         return "yellow";
     else if(d.key == "c) Not Free")
         return "red"; 
        });})

Also make sure remove fill setting in your css class since in some browser the css class take precedence over fill attribute.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vary the colors of same-series data markers in a chart
In a chart, click to select the data series for which you want to change the colors. · Click the Format tab and...
Read more >
How to color chart bars based on their values
How to color chart bars based on their values · Press with right mouse button on on a column on the chart. ·...
Read more >
How to create a Bar Chart with color ranges in Excel
One of the design strategies to enhance the dimensionality of bar charts is to use color to encode another dimension in the data....
Read more >
Create a color grouping chart (color bars by value) in Excel
In some cases, you may need to create a column or bar chart with different colors for the bars based on values. As...
Read more >
How to Color Bar Chart by Category in Excel (2 Easy Methods)
1. Using IF Function to Color a Bar Chart by Category in Excel · It opens the Format Axis task pane. Now, click...
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