Dashboards & Visualizations

change background color of a single value result according to the text in simple xml

smolcj
Builder

Hi,
i have a single value module which returns either a yes or a no, how to change their color to green if the result is NO and red if it is YES. i am working in simple xml. i tried changing the application.css with
..singleResult .YES{
color: #FF0000;
}
plese help
Thank you

Tags (2)
0 Karma
1 Solution

jonuwz
Influencer

Lets say your search outputs a field called 'yes_or_no' that contains 'YES' or 'NO' (probably using rangemap)

Your dashboard would look like :

<?xml version='1.0' encoding='utf-8'?>
<dashboard>
  <label>Example</label>
  <row>
    <single>
      <searchTemplate>... | table yes_or_no</searchTemplate>
      <title>YES or NO</title>
      <option name="classField">yes_or_no</option>
    </single>
  </row>
</dashboard>

Its the classField parameter that determines what css class it'll pick up

And your application.css would look like :

.SingleValue .NO .singleResult {
    color: #ffb800;
}

.SingleValue .YES .singleResult {
    color: #ffb800;
}

You need to restart splunk if application.css has just been created for the 1st time.

View solution in original post

jonuwz
Influencer

Lets say your search outputs a field called 'yes_or_no' that contains 'YES' or 'NO' (probably using rangemap)

Your dashboard would look like :

<?xml version='1.0' encoding='utf-8'?>
<dashboard>
  <label>Example</label>
  <row>
    <single>
      <searchTemplate>... | table yes_or_no</searchTemplate>
      <title>YES or NO</title>
      <option name="classField">yes_or_no</option>
    </single>
  </row>
</dashboard>

Its the classField parameter that determines what css class it'll pick up

And your application.css would look like :

.SingleValue .NO .singleResult {
    color: #ffb800;
}

.SingleValue .YES .singleResult {
    color: #ffb800;
}

You need to restart splunk if application.css has just been created for the 1st time.

MuS
Legend

thanks for this, I was just wondering yesterday how to do this and now it is done. splunk-base - what great source!

0 Karma

smolcj
Builder

Thank youu

0 Karma

jonuwz
Influencer

In that case classField should be x.
class field is the field in the search that sets the class.

yes_or_no isn't a field in your search

smolcj
Builder

i am using a form with a dropdown box and my single value panel is like

  


index=main source=$sources$ |eval x=if(severity="FATAL","YES","NO") | sort - x |table x |head 1

FATAL :

yes_or_no

changed application.css with above code. still the single result is in black in color.

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...