<?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 Change Cell Color Based on Range in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410741#M26967</link>
    <description>&lt;P&gt;I have a table that lists some percentages. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Priority | Minimum | Percentage
1           95.00%     95.23%
2           98.00%     97.23%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to color the cells in the Percentage column based on the values from Minimum. &lt;BR /&gt;
For example, in Priority 1, I need to color the Percentage cell with green because it has exceeded minimum baseline.&lt;BR /&gt;
In Priority 2, I need to color the cell grey because it did not meet minimum percentage.&lt;/P&gt;

&lt;P&gt;I've seen people do something like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;format type="color" field="Percentage"&amp;gt;
          &amp;lt;colorPalette type="expression"&amp;gt;case(value == "No Data", "#898989", value &amp;gt; 90.00, "#36D734")&amp;lt;/colorPalette&amp;gt;
        &amp;lt;/format&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, due to that each Priority has a different minimum percentage, I need to set rules per Priority. &lt;BR /&gt;
How should I achieve this?&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jan 2019 04:13:36 GMT</pubDate>
    <dc:creator>dojiepreji</dc:creator>
    <dc:date>2019-01-17T04:13:36Z</dc:date>
    <item>
      <title>Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410741#M26967</link>
      <description>&lt;P&gt;I have a table that lists some percentages. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Priority | Minimum | Percentage
1           95.00%     95.23%
2           98.00%     97.23%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to color the cells in the Percentage column based on the values from Minimum. &lt;BR /&gt;
For example, in Priority 1, I need to color the Percentage cell with green because it has exceeded minimum baseline.&lt;BR /&gt;
In Priority 2, I need to color the cell grey because it did not meet minimum percentage.&lt;/P&gt;

&lt;P&gt;I've seen people do something like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;format type="color" field="Percentage"&amp;gt;
          &amp;lt;colorPalette type="expression"&amp;gt;case(value == "No Data", "#898989", value &amp;gt; 90.00, "#36D734")&amp;lt;/colorPalette&amp;gt;
        &amp;lt;/format&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, due to that each Priority has a different minimum percentage, I need to set rules per Priority. &lt;BR /&gt;
How should I achieve this?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 04:13:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410741#M26967</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-01-17T04:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410742#M26968</link>
      <description>&lt;P&gt;Hi @dojiepreji&lt;/P&gt;

&lt;P&gt;Please check this solution&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/661894/how-to-color-cell-contents-with-css-and-js.html#answer-661940"&gt;https://answers.splunk.com/answers/661894/how-to-color-cell-contents-with-css-and-js.html#answer-661940&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 06:21:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410742#M26968</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-01-17T06:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410743#M26969</link>
      <description>&lt;P&gt;@dojiepreji refer to the following answer by @kamlesh_vaghela to add table cell color of one field depending on other field value:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/661894/how-to-color-cell-contents-with-css-and-js.html#answer-661940"&gt;https://answers.splunk.com/answers/661894/how-to-color-cell-contents-with-css-and-js.html#answer-661940&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 06:23:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410743#M26969</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-01-17T06:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410744#M26970</link>
      <description>&lt;P&gt;Hi @dojiepreji&lt;/P&gt;

&lt;P&gt;Here is the sample code &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;table_cell_color_demo.xml&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="table.js" stylesheet="table.css"&amp;gt;
   &amp;lt;label&amp;gt;Table Cell Color Demo&amp;lt;/label&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;table id="custom_table"&amp;gt;
         &amp;lt;search&amp;gt;
           &amp;lt;query&amp;gt;| makeresults 
| eval Priority=1, Minumum="95.00%", Percentage = "95.23%" 
| append 
    [| makeresults 
    | eval Priority=2, Minumum="98.00% ", Percentage = "97.23%"] 
| eval min = Minumum, per = Percentage 
| convert rmunit(min), rmunit(per) 
| eval result = if(min&amp;lt;per,"high","low") | eval Priority = Priority."|".result
| table Priority, Minumum, Percentage, min, per,result&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;/search&amp;gt;
         &amp;lt;option name="count"&amp;gt;5&amp;lt;/option&amp;gt;
         &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
         &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
         &amp;lt;fields&amp;gt;Priority, Minumum, Percentage&amp;lt;/fields&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;&lt;CODE&gt;table.js&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) {

     var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
         canRender: function(cell) {
             return _(['Priority','Minumum','Percentage']).contains(cell.field);
         },
         render: function($td, cell) {
             var label = cell.value.split("|")[0];
             var val = cell.value.split("|")[1];

               if(val=="high" || val=="low" )
               {
                   $td.html("&amp;lt;div class='css_for_"+label+"_"+val+"'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
               }
               else
               {
                    $td.html("&amp;lt;div class='align_center'&amp;gt;"+label+"&amp;lt;/div&amp;gt;")
               }

         }
     });

     //List of table IDs to add icon
     var tableIDs = ["custom_table"];
     for (i=0;i&amp;lt;tableIDs.length;i++) {
         var sh = mvc.Components.get(tableIDs[i]);
         if(typeof(sh)!="undefined") {
             sh.getVisualization(function(tableView) {
                 // Add custom cell renderer and force re-render
                 tableView.table.addCellRenderer(new CustomRangeRenderer());
                 tableView.table.render();
             });
         }
     }    
 });    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;table.css&lt;/CODE&gt;  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/*Define color as per your requirement*/

/*Priority 1 Minumum &amp;lt; Percentage */
 .css_for_1_high {         
 background-color:#008000;
 }

/*Priority 1 Minumum &amp;gt; Percentage */
 .css_for_1_low { 
 background-color:#004d4d;
 }

/*Priority 2 Minumum &amp;lt; Percentage */
 .css_for_2_high { 
 background-color: #00e6e6;
 }

/*Priority 2 Minumum &amp;gt; Percentage */
  .css_for_2_low { 
 background-color:#A8A8A8;
 }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;Sample Screen&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://ibb.co/VQDv6CQ"&gt;&lt;IMG src="https://i.ibb.co/KL79nsL/table.png" alt="table" /&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 14:08:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410744#M26970</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-01-17T14:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410745#M26971</link>
      <description>&lt;P&gt;@dojiepreji Whether it works?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 09:28:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410745#M26971</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-01-18T09:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410746#M26972</link>
      <description>&lt;P&gt;It worked, thank you. &lt;BR /&gt;
What if I want the Percentage column to be colored instead?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 04:57:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410746#M26972</guid>
      <dc:creator>dojiepreji</dc:creator>
      <dc:date>2019-01-24T04:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410747#M26973</link>
      <description>&lt;P&gt;Hi guys,&lt;BR /&gt;
I am struggling to get this solution to work.  I copy&amp;amp;pasted the code above exactly as is but cannot get any colors to show in the table.  Here is the order I followed, is there something out of step I am missing?&lt;/P&gt;

&lt;P&gt;1) Placed xml in /opt/splunk/etc/apps/search/local/data/ui/views/table_cell_color_demo.xml&lt;BR /&gt;
2) Placed jss and css in:&lt;BR /&gt;
/opt/splunk/etc/apps/search/appserver/static/table.js&lt;BR /&gt;
/opt/splunk/etc/apps/search/appserver/static/table.css&lt;/P&gt;

&lt;P&gt;3) splunk restart splunkweb&lt;BR /&gt;
4) refreshed dashboard&lt;BR /&gt;
* table displays but no color&lt;/P&gt;

&lt;P&gt;What am i doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410747#M26973</guid>
      <dc:creator>damonmanni</dc:creator>
      <dc:date>2020-09-29T23:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Change Cell Color Based on Range</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410748#M26974</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Are you getting any js error in the background&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 09:12:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Change-Cell-Color-Based-on-Range/m-p/410748#M26974</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-04-02T09:12:26Z</dc:date>
    </item>
  </channel>
</rss>

