How can I set chart colors consistently by series name?


(Arthur Smith) #1

In dashboard lookml there is a “series_color” field that lets you set the color based on the name of the series (the value of the pivot dimension) in a chart:

  series_name: css_color

We have a series of products that are each closely linked with specific colors and we would really like to be able to consistently and automatically color any charts based on those linked colors. There doesn’t seem to be a way to specify this in the view model files - we end up editing each visualization (Look) independently to set the colors the way we want. If we could allow the above dashboard lookml color settings to also be applied at the level of a single dimension in a view file that would be really helpful.

Or maybe there’s already a way to do this?

(Paola) #2

Hey @apsmith

We currently don’t have a way to set the color on the visualizations in the LookML - but I can definitely pass this along to our product team for you!

(Arthur Smith) #3

Thanks, let me know if any clarification is needed on this!


More generally, is there some trick to having series color coded consistently across Looks on the same Dashboard if you don’t particularly care which series is associated with which color so long as they’re always the same?

(romain.ducarrouge) #5

For this case there is an option in the /admin page where you can define one color palette to use for all the Looks!
We have this article here that explains this feature.

(Arthur Smith) #6

I should probably note that I found a way to do this relatively easily as follows:
(1) Set up a default color palette as @romain.ducarrouge suggests.
(2) Set up the dimension in question (for the product) as a “case when” list, in the standard order we prefer - this ensures that all products are listed (via dimension fill) in each query that doesn’t filter on the product, even if there’s no data for one or more of them
(3) Then whenever a chart uses a pivot on the product dimension (and no other pivot) it is automatically colored according to the default scheme, consistently.

This works reasonably well for our purposes.

(Aleksandrs Vedernikovs) #7

Hi @apsmith,

Thanks for sharing this pattern with our customers. We are glad it works for you well.

(Michelle Ogburn) #8

A follow-up to @apsmith suggestion about “case when” lists.

Is it possible to use a “case when” list in a Custom Dimension? So far I’m not finding documentation for that. And I haven’t successfully stumbled on the syntax if it is possible.

(Arthur Smith) #9

I’m not sure what you mean by a “Custom Dimension”? I think that’s what we’re doing - here’s the syntax I’m using in the view file (which is included in others to provide this default dimension for many other views where the table has a “product” column):

view: full_product_list {
dimension: product {
case: {
when: {
sql: ${TABLE}.product = ‘A’ ;;
label: “A”
when: {
sql: ${TABLE}.product = ‘B’ ;;
label: “B”
when: {
sql: ${TABLE}.product = ‘C’ ;;
label: “C”



(romain.ducarrouge) #10

@mogburn, the code from Arthur is using the LookML code, defined in the View file directly and using the LookML case

If you wish to work with Custom Dimensions on the Explore directly, you are correct to think the use of case when is not possible. Instead you can implement nested if() like so:

if(${field} = "value1", "Tall", 
   if(${field} = "value2", "Medium", 

The above will be the Custom Dimension implementation of either:

LookML Case parameter:

case: {
  when: {
  sql: ${TABLE}.product = "value1" ;;
  label: "Tall"
  when: {
  sql: ${TABLE}.product = "value2" ;;
  label: "Medium"
else: "Short"


or Pure SQL code:

CASE WHEN ${field} = "value1" THEN "Tall"
WHEN ${field} = "value2" THEN "Medium"
ELSE "Short"

(Michelle Ogburn) #11

Thank you. And thank you for the nested If() syntax. That is what I tried first. None the less, I found a simple solution to the color problem…

From the visualization pane, open the Edit panel, Series Tab. In the customizations section, simply click on the color thumbnail. Choose the color for the series.

(ariel fogel) #12

I’m not sure whether this is exactly the same ask, but I find it frustrating how a change to a custom dimension will wreak havoc across the color schemes I’ve already set on dashboard visualizations. Specifically, it resets the colors in a nondeterministic way. This is especially frustrating for when I attempt to coordinate colors across different tiles pivoting on different dimensions that have some overlapping categories.

If there were a way to both define a color scheme and assign it to a dimension so that it deterministically assigns a color to a label, that would be incredibly helpful. For example:

case: {
  when: {
    sql: ${TABLE}.product = "value1" ;;
    label: "Tall"
    color: "#111111"

Alternatively, if there were a way to expose setting colors in a tile’s series via the API, I can write a script to do it rather than having to use the GUI (way more efficient).

A global palette is not a good use case for this problem as we need multiple color schemes, some with overlapping colors, to improve the semantics of the dashboard. Currently, unnecessary resources are expended having to recoordinate the entire dashboard manually whenever any change is made in developer mode.


I’d like to +1 this request, this would be extremely helpful. I’m running into the same situation as ariel.

(jeffrey.martinez) #14

Good to know @banjahman, I will make sure to add this +1 internally on your behalf!

(Laurent Stanevich) #15

This just seems like such a straightforward way to implement what’s basically a “table-stakes” feature in 2018.

Seriously – I couldn’t believe it when I started using Looker, and discovered there was no way to associate fixed colors to dimensions. +1