<?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 sort the display order of data inside a bar on a stacked bar chart in Splunk 6.2.1? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269779#M81193</link>
    <description>&lt;P&gt;We have a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... 
| eval week_start=relative_time(_time,"@w")
| eval week_label=strftime(week_start, "Week of %m-%d")
| chart sum(activityTime) AS hours BY customer week_label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which gives a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;customer    Week of 11-29  Week of 12-06
--------    -------------  -------------
Customer-A              8             10
Customer-B             15              7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And a stacked bar chart that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Customer-A [ 12-06    ][ 11-29  ]
Customer-B [ 12-06 ][ 11-29         ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, we want the data inside the bars to appear in date order as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Customer-A [ 11-29  ][ 12-06    ]
Customer-B [ 11-29         ][ 12-06 ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using | sort I can change the order of customers but I can't budge the display order of the elements inside each bar. How can I change the elements inside the bar to appear in date (also happens to be alpha) order? &lt;/P&gt;

&lt;P&gt;We are on 6.2.1&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2015 20:30:42 GMT</pubDate>
    <dc:creator>rgsage</dc:creator>
    <dc:date>2015-12-10T20:30:42Z</dc:date>
    <item>
      <title>How to sort the display order of data inside a bar on a stacked bar chart in Splunk 6.2.1?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269779#M81193</link>
      <description>&lt;P&gt;We have a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... 
| eval week_start=relative_time(_time,"@w")
| eval week_label=strftime(week_start, "Week of %m-%d")
| chart sum(activityTime) AS hours BY customer week_label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which gives a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;customer    Week of 11-29  Week of 12-06
--------    -------------  -------------
Customer-A              8             10
Customer-B             15              7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And a stacked bar chart that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Customer-A [ 12-06    ][ 11-29  ]
Customer-B [ 12-06 ][ 11-29         ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, we want the data inside the bars to appear in date order as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Customer-A [ 11-29  ][ 12-06    ]
Customer-B [ 11-29         ][ 12-06 ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using | sort I can change the order of customers but I can't budge the display order of the elements inside each bar. How can I change the elements inside the bar to appear in date (also happens to be alpha) order? &lt;/P&gt;

&lt;P&gt;We are on 6.2.1&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2015 20:30:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269779#M81193</guid>
      <dc:creator>rgsage</dc:creator>
      <dc:date>2015-12-10T20:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the display order of data inside a bar on a stacked bar chart in Splunk 6.2.1?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269780#M81194</link>
      <description>&lt;P&gt;The problem is that the chart will return the data with the columns headers sorted alphabetically, &lt;BR /&gt;
_time  week of 1-10, week of 1-17, week of 01-24 ...&lt;BR /&gt;
but the visualization with stacked columns will put the last ones on the bottom,. and the firs ones on the top&lt;/P&gt;

&lt;P&gt;A trick is to rename the title to add a number that will be sorted in the reverse order&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="_internal" admin source="*scheduler.log"  | eval week_start=relative_time(_time,"@w")
| eval week_number=strftime(week_start, "%U")
| eval year_number=strftime(week_start, "%Y")
| convert num(week_number) AS week_number num(year_number) AS year_number
| eval title_sort=10000-year_number-week_number
| eval week_label="(".title_sort.") ".strftime(week_start, "Week of %m-%d")
| eval hours=run_time/60/60
| chart sum(hours) by app week_label
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2016 00:00:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269780#M81194</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2016-02-23T00:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the display order of data inside a bar on a stacked bar chart in Splunk 6.2.1?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269781#M81195</link>
      <description>&lt;P&gt;Thank you. Since I am constrained to column-name alphabetical sort order inside the bar I ended up doing it like this (our search goes back up to 4 weeks which explains the magic 4 in eval title_sort below):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... earliest=@w-3d
...
| eval week_start=relative_time(_time,"@w")
| eval sort_start=relative_time(now(),"@w-3w")
| eval title_sort=4-round((week_start-sort_start) / (60*60*24*7), 0)
| eval week_label="(".title_sort.") ".strftime(week_start, "Week of %m-%d")
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which gives column titles like this that sort chronologically (reverse alphabetically) inside the bars:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(1) Week of 12-06
(2) Week of 11-29
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The title_sort index numbers are just a bit more palatable that the numbers generated by 10000-year_number-week_number.  &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:53:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-display-order-of-data-inside-a-bar-on-a-stacked/m-p/269781#M81195</guid>
      <dc:creator>rgsage</dc:creator>
      <dc:date>2020-09-29T08:53:54Z</dc:date>
    </item>
  </channel>
</rss>

