Can't get shape to render with correct color

Just starting out with Canvas so bear with me :slight_smile:

I am trying to get a box colored based on status, and here's what I have so far

filters
| essql 
  query="SELECT
 CASE WHEN LAST(\"kubernetes.pod.status.phase\", \"@timestamp\") = 'failed' THEN 0
      WHEN LAST(\"kubernetes.pod.status.phase\", \"@timestamp\") = 'pending' THEN 1
      ELSE 100 END as status,
 CASE WHEN LAST(\"kubernetes.pod.status.phase\", \"@timestamp\") = 'failed' THEN '#ff0000'
      WHEN LAST(\"kubernetes.pod.status.phase\", \"@timestamp\") = 'pending' THEN '#ffff00'
      ELSE '#00ff00' END as color,
 \"kubernetes.pod.name\" as podname
 FROM \"metricbeat-*\" 
WHERE
 \"kubernetes.app\" = 'proxy'
AND 
  \"kubernetes.pod.status.phase\" IS NOT NULL
GROUP BY
  podname"
| sort | shape "square" fill="{{rows.[0].color}}" border="rgba(255,255,255,0)" borderWidth=0 maintainAspect=false | render

I have verified that the query outputs the correct data, an dthe above expression works perfectly when I output the color in a "markdown" text. But the shape box remains black.

I feel like I am missing something fundamental here, but I'm not sure where to even start digging, and I can't find any examples of something similar in the docs.

Hi @rickardp,

Assuming the query outputs the correct data, I think the problem lies in the way you are trying to access {{rows.[0].color}} in the fill argument.

Fill is expecting a hex code, so it won't understand the handlebars template you are trying to give it; it's probably just thinking you provided a malformed color string, and falls back to black.

In order to get the correct hex code, you'll want to use the getCell function as a subexpression to pull the cell from the correct place:

fill={getCell column="color" r=0}

This is going to take the color value from the first row of results and pass it as the fill, which (I think) is what you are trying to do.

Hope this helps!

That works, thank you! I thought the Handlebars templates worked everywhere in the same way, but apparently not. Still learning as I go along :slight_smile:

No problem! Yeah the Handlebars templates are a feature of the Markdown element in Canvas specifically, but they are not a core feature of the expression language.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.