Conditional Colors in Bar Chart Using Dimension Values


I’ve just started using Looker and I created a histogram of two data series that are blended together. So I have 2 dimensions, “grouping” and “monetization”, and 1 measure, “percentage”. So a sample of the data would look like this:
Grouping Monetization Percentage
A $1.00 80%
B $1.00 75%
A $2.00 20%
B $2.00 25%

I’m currently displaying the data in a bar chart, and i have it ordered in the way that I want with the percentage values showing - so it’s mostly good. The issue I have is that I want to visually differentiate the two groupings, so I’d like to use the chart options to define a different color for the two groups. I was thinking green for grouping A, and blue for grouping B. Is this possible? I know I can do this in the LookML for the values, but I don’t know how to do this within a visualization, or if it’s even possible. Any help would be greatly appreciated!

1 Like

Sorry if this is a duplicate, I am new to this and couldn’t find anything that sounded similar.

I’d recommend pivoting your data by the ‘Grouping’ dimension. This will create one series for each grouping. You can learn more about pivoting in this document. Then you can control the color of each group using ‘Series Colors’ in the Style section of the visualizations.

Here’s something I whipped up to illustrate that. The dimensions that I chose are city and age, and the measure is count (percent of total).

This is what the chart looks like before pivoting:

And here’s what the chart looks like after pivoting:

It just so happens that our default colors are blue and green, but if you want to change it, you can use the legend text to populate the Series Colors section of the visualization settings.

Let me know if you have any questions about this!

That worked perfect, thank you!

Awesome! Sure thing!

Great post here. I wanted to ask what’s the best way to format the bar chart according to value. I’d like to display negative values in red and positive in green.

Any ideas? Thanks

Check out @brecht’s comment here:

The table calcs there ought to work great for this.

1 Like

Thanks a lot Izzy :slight_smile: It worked like magic!

1 Like