Good afternoon,
I need help changing the colors of two columns in my <panel>.
I need to change the colors of the "Values - Requested" and "Values - Retrieved" columns.
When the values in these two columns are the same, color the cell background green. And when they are different, color it red.
Does anyone know how to do this?
You have to a bit of a trick to do this, because you can't set a colour in one cell with a formula to compare the value of another cell, you can do it this way.
First you turn each of those values into a multi value cell, where the second value is the relationship with the other cell
``` Set a colour if they are the same/different ```
| eval colour=if('Valores - Solicitados'='Valores - Recuperados', "#00ff00",
"#ff0000")
``` Create each field as a multivalue field with the second value as colour ```
| eval 'Valores - Solicitados'=mvappend('Valores - Solicitados', colour)
| eval 'Valores - Recuperados'=mvappend('Valores - Recuperados', colour)
| fields - colour
Then you should use CSS to limit the display of those fields to only display the single value, add a hidden html panel with the CSS to hide the multivalue fields 2nd value - note here "coloured_cell" is the id of your table element.
<html depends="$hidden$">
<style>
#coloured_cell table tbody td div.multivalue-subcell[data-mv-index="1"]{
display: none;
}
</style>
</html>
You should set the id of your table as below
<table id="coloured_cell">
and then finally use the format specifier in the XML to set the colour
<format type="color" field="Valores - Solicitados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
<format type="color" field="Valores - Recuperados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
Here's a full example dashboard
<form version="1.1">
<label>Demo1</label>
<row>
<panel>
<html depends="$hidden$">
<style>
#coloured_cell table tbody td div.multivalue-subcell[data-mv-index="1"]{
display: none;
}
</style>
</html>
<table id="coloured_cell">
<title>Colouring a table cell based on it's relative comparison to another cell</title>
<search>
<query>| makeresults count=10
| fields - _time
| eval Result="Result"
| eval "Valores - Solicitados"=random() % 8, "Valores - Recuperados"=random() % 8
``` Set a colour if they are the same/different ```
| eval colour=if('Valores - Solicitados'='Valores - Recuperados', "#00ff00", "#ff0000")
``` Create each field as a multivalue field with the second value as colour ```
| eval "Valores - Solicitados"=mvappend('Valores - Solicitados', colour)
| eval "Valores - Recuperados"=mvappend('Valores - Recuperados', colour)
| fields - colour
| table Result "Valores - Solicitados" "Valores - Recuperados"
</query>
<earliest>-15m</earliest>
<latest>now</latest>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">100</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">row</option>
<option name="percentagesRow">false</option>
<option name="refresh.display">progressbar</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
<format type="color" field="Valores - Solicitados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
<format type="color" field="Valores - Recuperados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
</table>
</panel>
</row>
</form>
You have to a bit of a trick to do this, because you can't set a colour in one cell with a formula to compare the value of another cell, you can do it this way.
First you turn each of those values into a multi value cell, where the second value is the relationship with the other cell
``` Set a colour if they are the same/different ```
| eval colour=if('Valores - Solicitados'='Valores - Recuperados', "#00ff00",
"#ff0000")
``` Create each field as a multivalue field with the second value as colour ```
| eval 'Valores - Solicitados'=mvappend('Valores - Solicitados', colour)
| eval 'Valores - Recuperados'=mvappend('Valores - Recuperados', colour)
| fields - colour
Then you should use CSS to limit the display of those fields to only display the single value, add a hidden html panel with the CSS to hide the multivalue fields 2nd value - note here "coloured_cell" is the id of your table element.
<html depends="$hidden$">
<style>
#coloured_cell table tbody td div.multivalue-subcell[data-mv-index="1"]{
display: none;
}
</style>
</html>
You should set the id of your table as below
<table id="coloured_cell">
and then finally use the format specifier in the XML to set the colour
<format type="color" field="Valores - Solicitados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
<format type="color" field="Valores - Recuperados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
Here's a full example dashboard
<form version="1.1">
<label>Demo1</label>
<row>
<panel>
<html depends="$hidden$">
<style>
#coloured_cell table tbody td div.multivalue-subcell[data-mv-index="1"]{
display: none;
}
</style>
</html>
<table id="coloured_cell">
<title>Colouring a table cell based on it's relative comparison to another cell</title>
<search>
<query>| makeresults count=10
| fields - _time
| eval Result="Result"
| eval "Valores - Solicitados"=random() % 8, "Valores - Recuperados"=random() % 8
``` Set a colour if they are the same/different ```
| eval colour=if('Valores - Solicitados'='Valores - Recuperados', "#00ff00", "#ff0000")
``` Create each field as a multivalue field with the second value as colour ```
| eval "Valores - Solicitados"=mvappend('Valores - Solicitados', colour)
| eval "Valores - Recuperados"=mvappend('Valores - Recuperados', colour)
| fields - colour
| table Result "Valores - Solicitados" "Valores - Recuperados"
</query>
<earliest>-15m</earliest>
<latest>now</latest>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">100</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">row</option>
<option name="percentagesRow">false</option>
<option name="refresh.display">progressbar</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
<format type="color" field="Valores - Solicitados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
<format type="color" field="Valores - Recuperados">
<colorPalette type="expression">mvindex(value, 1)</colorPalette>
</format>
</table>
</panel>
</row>
</form>
IF( "Valores - Solicitados" == "Valores - Recuperados" , Color Verde, Color Red)