<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can I color a cell based on condition? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310446#M19837</link>
    <description>&lt;P&gt;@shreyasathavale, were you able to test out the run anywhere dashboard as per your use case?&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 19:21:17 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-01T19:21:17Z</dc:date>
    <item>
      <title>Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310443#M19834</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I have 2 columns that shows run times for a job (ReallDuration and RunDuration) . Real duration is how much time the job should run and RunDuration is job ran for how much duration. The values are like RunDuraion=00:35:45.0000 and RealDuration=00:28:35 . I want to color the cell of RunDuration as Red if RunDuration &amp;gt; RealDuration using simple xml.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 08:42:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310443#M19834</guid>
      <dc:creator>shreyasathavale</dc:creator>
      <dc:date>2017-10-18T08:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310444#M19835</link>
      <description>&lt;P&gt;is there a little paintbrush to the top right of your column? if so, click that and select color/range&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 14:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310444#M19835</guid>
      <dc:creator>myriadic</dc:creator>
      <dc:date>2017-10-18T14:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310445#M19836</link>
      <description>&lt;P&gt;@shreyasathavale, you can use &lt;STRONG&gt;Splunk Dashboard Examples App&lt;/STRONG&gt; to take a look at &lt;STRONG&gt;Table Row Highlighting&lt;/STRONG&gt; example.&lt;/P&gt;

&lt;P&gt;In your case you would need to convert RealDuration to same format as RunDuration i.e. &lt;CODE&gt;HH:MM:SS.%4N&lt;/CODE&gt; and then use &lt;CODE&gt;strptime()&lt;/CODE&gt; to convert them to epoch time (so that they can be used for evaluating numerical difference) using &lt;CODE&gt;%H:%M:%S.%4N&lt;/CODE&gt;. Once you calculate the Difference, the same can be used to apply row color as per your use case. Following is the run any where search example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval RunDuration="00:35:45.0000"
|  eval RealDuration="00:28:35".".0000"
|  append
    [|  makeresults
|  eval RunDuration="00:25:20.0000"
|  eval RealDuration="00:30:50".".0000"]
|  append
    [|  makeresults
|  eval RunDuration="00:40:30.0000"
|  eval RealDuration="00:35:40".".0000"]
|  fields - _time
|  eval RunDurationEpoch=strptime(RunDuration,"%H:%M:%S.%4N")
|  eval RealDurationEpoch=strptime(RealDuration,"%H:%M:%S.%4N")
|  eval diffEpoch=RunDurationEpoch-RealDurationEpoch
|  fields - RunDurationEpoch RealDurationEpoch
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Commands till &lt;CODE&gt;| fields - _time&lt;/CODE&gt; generate mock data as per your requirement. You would need to use your existing Splunk query instead. Remaining pipes calculate required difference in Epoch Time for RunDuration and RealDuration. You will also need to add &lt;CODE&gt;%4N&lt;/CODE&gt; to RealDuration to have both time fields in similar format. If RunDuration &lt;CODE&gt;%4N&lt;/CODE&gt; is always &lt;CODE&gt;0000&lt;/CODE&gt;, you can ignore the following and also just use &lt;CODE&gt;"%H:%M:%S"&lt;/CODE&gt; in your &lt;CODE&gt;strptime()&lt;/CODE&gt; functions.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  eval RealDuration=RealDuration.".0000"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Final command &lt;CODE&gt;|  fields - RunDurationEpoch RealDurationEpoch&lt;/CODE&gt; removes Epoch times not required.&lt;/P&gt;

&lt;P&gt;Following is the Run anywhere dashboard code. &lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3672i7D8A0C0D0414B705/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;1) JavaScript and CSS files have been used in the dashboard i.e. &lt;CODE&gt;script="table_row_highlighting_numeric_diff.js" stylesheet="table_decorations.css"&lt;/CODE&gt;&lt;BR /&gt;
2) Table has been given id="highlight"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="table_row_highlighting.js" stylesheet="table_decorations.css"&amp;gt;
  &amp;lt;label&amp;gt;Color Based on Two Columns&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Color Table Row Based on duration difference&amp;lt;/title&amp;gt;
      &amp;lt;table id="highlight"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;|  makeresults
|  eval RunDuration="00:35:45.0000"
|  eval RealDuration="00:28:35".".0000"
|  append
    [|  makeresults
|  eval RunDuration="00:25:20.0000"
|  eval RealDuration="00:30:50".".0000"]
|  append
    [|  makeresults
|  eval RunDuration="00:40:30.0000"
|  eval RealDuration="00:35:40".".0000"]
|  fields - _time
|  eval RunDurationEpoch=strptime(RunDuration,"%H:%M:%S.%4N")
|  eval RealDurationEpoch=strptime(RealDuration,"%H:%M:%S.%4N")
|  eval diffEpoch=RunDurationEpoch-RealDurationEpoch
|  fields - RunDurationEpoch RealDurationEpoch&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Javascript file &lt;CODE&gt;table_row_highlighting.js&lt;/CODE&gt; (based on the Splunk Dashboard Examples App)&lt;BR /&gt;
&lt;CODE&gt;PS: Somehow the JavaScript to apply custom Table Row Classes was getting overridden with Splunk Default Table Renderer. Hence colors were not applying. I have added 1 sec delay in adding table row class based on cell class using setTimeOut() JavaScript function. Please adjust or remove as per your use case.&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

     // Row Coloring by Numeric Comparison of Epoch Time Value in HH:MM:SS.%4N

    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            // Enable this custom cell renderer for diffEpoch field
            return _(['diffEpoch']).contains(cell.field);
        },
        render: function($td, cell) {
            // Add a class to the cell based on the returned value
            var value = cell.value;
            // Update the cell content with numeric diffEpoch value HH:MM:SS.%4N
            $td.text(value).addClass('numeric');

            // Apply interpretation for diffEpoch field
            if (cell.field === 'diffEpoch') {
                if (value &amp;gt;= 0) {
                        $td.addClass('range-cell').addClass('range-severe');
                }
            }
        }
    });

    mvc.Components.get('highlight').getVisualization(function(tableView) {
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addCellRenderer(new CustomRangeRenderer());
        tableView.on('rendered', function() {
            // Add a delay to ensure Custom Render applies to row without getting overridden with built in reder.
            setTimeout(function() { 
                tableView.$el.find('td.range-cell').each(function() {
                        $(this).parents('tr').addClass(this.className);
                        console.log("Applying Class",this.className);
                });
            }, 100);
        });
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the &lt;CODE&gt;table_decorations.css&lt;/CODE&gt; code similar to the one used in example.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/* Row Coloring */

#highlight tr td {
    background-color: #65A637 !important;
}

#highlight tr.range-elevated td {
    background-color: #F7BC38 !important;
    font-weight: bold;
}

#highlight tr.range-severe td {
    background-color: #D93F3C !important;
    font-weight: bold;
}

#highlight .table td {
    border-top: 1px solid #fff;
}

#highlight td.range-severe, td.range-elevated {
    font-weight: bold;
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;PS: Since this example uses JavaScript and CSS static files. It might require you to Refresh/Restart Splunk and also clear your Internet Browser history for changes to reflect.&lt;/CODE&gt;&lt;BR /&gt;
Please try out and confirm.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2017 16:54:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310445#M19836</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-20T16:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310446#M19837</link>
      <description>&lt;P&gt;@shreyasathavale, were you able to test out the run anywhere dashboard as per your use case?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 19:21:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310446#M19837</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-01T19:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310447#M19838</link>
      <description>&lt;P&gt;We've run into the same issue with the table row highlighting no longer working in some cases after a Splunk upgrade.  We've implemented the setTimeout which ultimately accomplishes the goal, but it also results in a flash of the default color which is then overlaid with the correct color.  Since we use a number of auto-refreshing panels, the flashes looks rather unprofessional.  We've also found that the time value needs to be adjusted based on how long the corresponding search takes to finish.  If you set the number too low, the correct colors never show up.  If you set it too high, the brief default color is more noticeable.  This makes it very difficult to know which number to choose since dashboards can run in several different environments.  Is there another alternative to this?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 21:21:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310447#M19838</guid>
      <dc:creator>rrobe07</dc:creator>
      <dc:date>2018-02-05T21:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310448#M19839</link>
      <description>&lt;P&gt;Incidentally, version 6.5.4 works fine in all cases with no timeout code needed at all.  When we attempted to upgrade to 6.6.4, that's when this issue started.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 22:34:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310448#M19839</guid>
      <dc:creator>rrobe07</dc:creator>
      <dc:date>2018-02-05T22:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310449#M19840</link>
      <description>&lt;P&gt;Yes we also noted the same. It has definitely been called out on separate question with a BUG tag.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/614788/splunk-dashboard-examples-table-row-highlighting-b.html?childToView=615859#answer-615859"&gt;https://answers.splunk.com/answers/614788/splunk-dashboard-examples-table-row-highlighting-b.html?childToView=615859#answer-615859&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If you have a valid Splunk Entitlement you can reach out to Splunk Support.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 15:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310449#M19840</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-02-13T15:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310450#M19841</link>
      <description>&lt;P&gt;Hi @niketnilay ,&lt;/P&gt;

&lt;P&gt;I tried the custom script you provided above to add custom color to my table (id= mytable) rows based on the value in the Column "Severity" (Red for critical, Amber for High....), however for some reason it's not providing me intended results. &lt;/P&gt;

&lt;P&gt;JS:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
     'underscore',
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/tableview',
     'splunkjs/mvc/simplexml/ready!'
 ], function(_, $, mvc, TableView) {

     var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
         canRender: function(cell) {

             return _(['Severity']).contains(cell.field);
         },
         render: function($td, cell) {

             var value = cell.value;


             $td.text(value).addClass('string');


             if (cell.field === 'Severity') {

                 if (value == "Critical") {
                     $td.addClass('range-cell').addClass('Critical');
                 }
                 if (value == 'High' ) {
                     $td.addClass('range-cell').addClass('High');
                 }

             }


         }
     });

     mvc.Components.get('mytable').getVisualization(function(tableView) {

         tableView.on('rendered', function() {

             setTimeout(function(){    

                 tableView.$el.find('td.range-cell').each(function() {
                     $(this).parents('tr').addClass(this.className);
                 });
             },100);
         });

         tableView.addCellRenderer(new CustomRangeRenderer());
     });
 });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Stylesheet:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; #highlight tr.Critical td {
     background-color: #FF0000 !important;
 }

 #highlight tr.High td {
     background-color: #FF7F50 !important;
 }


 #highlight tr.High, tr.Critical{
     font-weight: bold;
 }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any idea what's going wrong here ?&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 11:10:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310450#M19841</guid>
      <dc:creator>qbolbk59</dc:creator>
      <dc:date>2018-10-13T11:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310451#M19842</link>
      <description>&lt;P&gt;@qbolbk59 seems like your table id is &lt;CODE&gt;mytable&lt;/CODE&gt; but you are trying to apply CSS override for incorrect table id (&lt;CODE&gt;highlight&lt;/CODE&gt; which was applicable to the example in my previous answer). So please try the following CSS instead!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;      #mytable tr.Critical td {
          background-color: #FF0000 !important;
      }

      #mytable tr.High td {
          background-color: #FF7F50 !important;
      }


      #mytable tr.High, tr.Critical{
          font-weight: bold;
      }
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 12:30:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310451#M19842</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-18T12:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310452#M19843</link>
      <description>&lt;P&gt;Hi @niketnilay ,,,, That was so stupid of me.... &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks for pointing out the mistake. However after changing the css, the results are still not as i intended. I can assure that the js and CSS are loaded in the dashboard, but somehow the color codes that i have provided are not getting loaded. All the rows are having same color. &lt;BR /&gt;
I tried clearing the browser history/cache, but no luck. &lt;/P&gt;

&lt;P&gt;sorry if my queries are to naive.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 13:22:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310452#M19843</guid>
      <dc:creator>qbolbk59</dc:creator>
      <dc:date>2018-10-18T13:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can I color a cell based on condition?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310453#M19844</link>
      <description>&lt;P&gt;If this is non prod have you also tried &lt;CODE&gt;_bump&lt;/CODE&gt; or &lt;CODE&gt;debug/refresh&lt;/CODE&gt;? I have tested out this on Splunk 7.2 and seems to work fine!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 14:00:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Can-I-color-a-cell-based-on-condition/m-p/310453#M19844</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-10-18T14:00:40Z</dc:date>
    </item>
  </channel>
</rss>

