<?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 How to create a bar chart with colors based on an external field? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428432#M28216</link>
    <description>&lt;P&gt;Im trying to create bar chart base don table and to color the columns by field that is not part of the table.&lt;BR /&gt;
For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**my_search... | eval risk_order=case(app_risk=="High",0, app_risk=="Critical",1) | stats count as "Logs" by appi_name ,risk_order | sort 10 -risk_order -"Logs" | table appi_name , "Logs"**
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I visualize it, I see that every bar as the same color (which is based on field "Logs").&lt;BR /&gt;
&lt;STRONG&gt;I would like to change the color of the bar based on app_risk field.&lt;/STRONG&gt;&lt;BR /&gt;
each value of app_risk should use different color.&lt;/P&gt;

&lt;P&gt;How can I do it?&lt;/P&gt;</description>
    <pubDate>Tue, 28 Aug 2018 08:27:57 GMT</pubDate>
    <dc:creator>shayhibah</dc:creator>
    <dc:date>2018-08-28T08:27:57Z</dc:date>
    <item>
      <title>How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428432#M28216</link>
      <description>&lt;P&gt;Im trying to create bar chart base don table and to color the columns by field that is not part of the table.&lt;BR /&gt;
For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**my_search... | eval risk_order=case(app_risk=="High",0, app_risk=="Critical",1) | stats count as "Logs" by appi_name ,risk_order | sort 10 -risk_order -"Logs" | table appi_name , "Logs"**
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I visualize it, I see that every bar as the same color (which is based on field "Logs").&lt;BR /&gt;
&lt;STRONG&gt;I would like to change the color of the bar based on app_risk field.&lt;/STRONG&gt;&lt;BR /&gt;
each value of app_risk should use different color.&lt;/P&gt;

&lt;P&gt;How can I do it?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 08:27:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428432#M28216</guid>
      <dc:creator>shayhibah</dc:creator>
      <dc:date>2018-08-28T08:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428433#M28217</link>
      <description>&lt;P&gt;What is your current output? Can you add mock screenshot of current and expected output?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 08:47:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428433#M28217</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-28T08:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428434#M28218</link>
      <description>&lt;P&gt;right now it looks like this:&lt;BR /&gt;
every appi_name has the same color (which is based on "logs" field)&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://serving.photos.photobox.com/63538196fb7740356a1322b5c50cc9582308486897bfacfa2b47aafe372624b47afcae1b.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;expected output will be that the 2 upper bars will be in red and the other in orange (since only the first 2 have app_risk =1)&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 08:55:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428434#M28218</guid>
      <dc:creator>shayhibah</dc:creator>
      <dc:date>2018-08-28T08:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428435#M28219</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;You should do 2 things:&lt;/P&gt;

&lt;P&gt;In the search command, you should add the following:  ....  |chart count  as total by app_risk,risk_order    | eval redCount = if(app_risk=="high",total,0) | eval greenCount = if(app_risk=="Critical", total, 0) | fields  Age redCount greenCount&lt;/P&gt;

&lt;P&gt;And then in the xml you should add this option for example in the considered panel : {"redCount":0xFF0000,"greenCount":0x73A550}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:02:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428435#M28219</guid>
      <dc:creator>mkamal18</dc:creator>
      <dc:date>2020-09-29T21:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428436#M28220</link>
      <description>&lt;P&gt;&lt;STRONG&gt;[UPDATED ANSWER]&lt;/STRONG&gt; &lt;BR /&gt;
Adding logic for sorting the results&lt;/P&gt;

&lt;P&gt;1) &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats" target="_blank"&gt;streamstats&lt;/A&gt; command is used to add serial number column after results are sorted as per need.&lt;BR /&gt;
2) &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConversionFunctions#printf.28.22format.22.2Carguments.29" target="_blank"&gt;printf()&lt;/A&gt; evaluation function is used to pad with zeros (2 zeros in the example below), to allow string sort of results up-to 2 digits of precision.&lt;BR /&gt;
3) Final pipe with &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29" target="_blank"&gt;replace()&lt;/A&gt; evaluation function is used to remove padded serial number from result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level IN ("ERROR","WARN")
 | stats count by component log_level
 | eval log_level=case(log_level=="ERROR",0,log_level=="WARN",1)
 | sort 10 - log_level count
 | streamstats count as sno
 | eval component=printf("%02d",sno).component
 | fields - sno
 | xyseries component log_level count
 | fillnull value=0 "0","1"
 | rename "0" as "ERROR" "1" as "WARN"
 | eval component=replace(component,"^\d+","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/100240"&gt;@shayhibah&lt;/a&gt;, your screenshot did not get uploaded (may be you missed hitting the enter key before and after attached image).&lt;/P&gt;

&lt;P&gt;However, based on your sample code provided you can try the following run anywhere example based on Splunk's _internal index which has &lt;CODE&gt;component&lt;/CODE&gt; field instead of &lt;CODE&gt;appi_name&lt;/CODE&gt; and &lt;CODE&gt;log_level&lt;/CODE&gt; instead of &lt;CODE&gt;app_risk&lt;/CODE&gt;. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level IN ("ERROR","WARN")
| stats count by component log_level
| eval log_level=case(log_level=="ERROR",0,log_level=="WARN",1)
| sort 10 - log_level count
| xyseries component log_level count
| fillnull value=0 "0","1"
| rename "0" as "ERROR" "1" as "WARN"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xyseries" target="_blank"&gt;xyseries&lt;/A&gt; command to invert the table to plot results as per requirement. The &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/fillnull" target="_blank"&gt;fillnull&lt;/A&gt; command has been used to place 0 value instead of null. The &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rename" target="_blank"&gt;rename&lt;/A&gt; command in he final pipe gives the columns a meaningful name i.e. &lt;CODE&gt;ERROR and WARN instead of 0 and 1  respectively&lt;/CODE&gt; in the given example.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:04:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428436#M28220</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T21:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428437#M28221</link>
      <description>&lt;P&gt;Thank you @niketnilay, it works!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 09:38:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428437#M28221</guid>
      <dc:creator>shayhibah</dc:creator>
      <dc:date>2018-08-28T09:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428438#M28222</link>
      <description>&lt;P&gt;@niketnilay &lt;BR /&gt;
Right now the data is sorted by alphabetical - the sort isn't working.&lt;BR /&gt;
Do you have any idea for this one?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 09:53:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428438#M28222</guid>
      <dc:creator>shayhibah</dc:creator>
      <dc:date>2018-08-28T09:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428439#M28223</link>
      <description>&lt;P&gt;@shayhibah I have updated my answer with the sorting logic. Try out and confirm!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 13:51:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428439#M28223</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-28T13:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428440#M28224</link>
      <description>&lt;P&gt;works perfectly! I appreciate it Niket&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 14:21:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428440#M28224</guid>
      <dc:creator>shayhibah</dc:creator>
      <dc:date>2018-08-28T14:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428441#M28225</link>
      <description>&lt;P&gt;Glad it worked... do up vote &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 15:03:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428441#M28225</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-08-28T15:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a bar chart with colors based on an external field?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428442#M28226</link>
      <description>&lt;P&gt;This worked great for me. Thanks @niketnilay &lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 00:55:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-bar-chart-with-colors-based-on-an-external-field/m-p/428442#M28226</guid>
      <dc:creator>azulgrana</dc:creator>
      <dc:date>2019-12-30T00:55:21Z</dc:date>
    </item>
  </channel>
</rss>

