Conditional coloring Kibana canvas

Hi, I'm want to change the color of the bars here depending on the value of "Primary channel " . i may have 12 values in "Primary channel" . the graph is displayed in real time so the color changing must be updated ( i want that "y" values be depending on Primary_channel)

this is my trial but it doesn't work

filters
| esdocs index="sagem*" fields="@timestamp, txopNew5" sort=", desc" query=""
| pointseries x="@timestamp" y="first(txopNew5)"
| mapColumn "txopNew5" 
  fn={switch
    case if={any {getCell "Primary_Channel5" | compare "lt" to=23} then="red"}
    case if={any {getCell "Primary_Channel5" | compare "gt" to=35} then="green"}} 
| plot defaultStyle={seriesStyle bars="3" lines="0" points="0"} legend="nw" palette={palette "#7ECAE3" "#003A4D" gradient=true} xaxis=true 
  font={font size=14 family="'Open Sans', Helvetica, Arial, sans-serif" color="#000000" align="left"} seriesStyle={seriesStyle}
| render

Hi @Kadhem

I'm not sure I follow completely what you are trying to do.

Where is Primary_Channel coming from? You are doing an esdocs query and getting @timestamp

Are you wanting separate bars for each different channel and those are colored according to the channel? Please explain a little further what you are trying to accomplish. (Maybe a simple example with data?)

1 Like

Primary_channel and Txop ( Y axis) are from the same index . this values are parsed in real-time . I want to set kind of link between these two separated values :when the value of Primary-channel changes the bars must change the color. I may have 12 different values in the Primary_channel so 12 colors.
Example

T=1s : Primary_Channel = 52  ==> Bars are colored in green 
T=30s : Primary_Channel = 20  ==> Bars are colored in red
.
.
.

Hi @Kadhem

Thanks, I understand what you're trying to do now.

You'll need to just make sure that you pull in the channel and the value from the query.

Something along these lines should work, just will need to build out the switch to set the appropriate colors.

filters
| essql 
  query="SELECT primary_channel, txop, '@timestamp' FROM \"sagem*\""
| mapColumn name="color" 
  expression={getCell column="primaryChannel" | switch case={case if={lt 23} then=0} default=1}
| pointseries x="@timestamp" y="txop" color="color"
| plot defaultStyle={seriesStyle bars=0.75} legend=false palette={palette "#FF0000" "#00FF00"}
| render
1 Like

thank you but here's what i got. i guess the Conditional statements is not working right

filters
| esdocs index="sagemcom*" fields="@timestamp, txopNew2, Primary_Channel" sort=", asc"
| mapColumn name="color" 
  expression={getCell column="Primary_Channel" | 
  switch case={case if={lt 91} then="black"
  else if={lte 94} then="blue"
  else "red"}}
| pointseries x="@timestamp" y="txopNew2" color="color"
| plot defaultStyle={seriesStyle bars=0.75} legend=false palette={palette "#FF0000" "#00FF00"}
| render

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