<?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: How to sort the items within a stacked bar chart by size? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145749#M40651</link>
    <description>&lt;P&gt;You script works in your case, but I cannot use the tstats command as it ignores my extracted fields. (Splunk does not know them)&lt;BR /&gt;
So I added  your script starting with line 2 between my chart-line and my addtotals line, because then the fields are known.&lt;BR /&gt;
All works, also the renaming, but when executing the xyseries, the sorting does not work - the items are not sorted.&lt;/P&gt;

&lt;P&gt;Which commands should I replace?&lt;/P&gt;</description>
    <pubDate>Wed, 01 Oct 2014 13:14:28 GMT</pubDate>
    <dc:creator>ulrich_track</dc:creator>
    <dc:date>2014-10-01T13:14:28Z</dc:date>
    <item>
      <title>How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145747#M40649</link>
      <description>&lt;P&gt;I have created a search to produce a stacked bar chart:&lt;BR /&gt;
(each shop sells the same items but in different quantities)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* |
chart count(ItemType) BY Shop ItemType |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and managed to sort the stacked bars by their total size:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;addtotals fieldname=total |
sort -total |
fields - total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I am missing is how to sort the items within each bar by size. It would also be ok, to sort only the largest bar and have the others follow the same order.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 13:44:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145747#M40649</guid>
      <dc:creator>ulrich_track</dc:creator>
      <dc:date>2014-09-30T13:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145748#M40650</link>
      <description>&lt;P&gt;This does roughly what you describe, but isn't very pretty.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count where index=* OR index=_* by sourcetype index | chart sum(count) as count by index sourcetype
| untable index sourcetype count | eventstats sum(count) as sum by sourcetype | sort + sum | streamstats dc(sourcetype) as num
| eval sourcetype = substr("000".num, -3, 3) . "_" . sourcetype | xyseries index sourcetype count
| addtotals fieldname=_total | sort - _total | fields - _total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first line sets up a dummy chart much like yours, counting events by two fields.&lt;/P&gt;

&lt;P&gt;The second like picks that chart apart and numbers the columns by their combined size, smallest first.&lt;/P&gt;

&lt;P&gt;The third line prepends that zero-padded number to the column name and reassembles the chart - now the columns are sorted lexicographically again, which happens to be the same as "sorted by combined size" due to the prepended number.&lt;/P&gt;

&lt;P&gt;The last line sorts the rows as you already described.&lt;/P&gt;

&lt;P&gt;Note, you can remove the ugly numbers prepended to the column names... but then the chart will fall back to lexicographical ordering based on the name alone, disregarding the order we created before.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2014 22:44:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145748#M40650</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-30T22:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145749#M40651</link>
      <description>&lt;P&gt;You script works in your case, but I cannot use the tstats command as it ignores my extracted fields. (Splunk does not know them)&lt;BR /&gt;
So I added  your script starting with line 2 between my chart-line and my addtotals line, because then the fields are known.&lt;BR /&gt;
All works, also the renaming, but when executing the xyseries, the sorting does not work - the items are not sorted.&lt;/P&gt;

&lt;P&gt;Which commands should I replace?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2014 13:14:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145749#M40651</guid>
      <dc:creator>ulrich_track</dc:creator>
      <dc:date>2014-10-01T13:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145750#M40652</link>
      <description>&lt;P&gt;Replacing &lt;CODE&gt;tstats&lt;/CODE&gt; is indeed no problem, that's just my dummy data.&lt;/P&gt;

&lt;P&gt;For debugging, backtrack from the rear by removing most commands, then adding them back one by one.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2014 15:24:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145750#M40652</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-01T15:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145751#M40653</link>
      <description>&lt;P&gt;I did - it works until the xyseries command. I was searching for an alternative like chart, but that doesn't display any chart. xyseries seems to be the solution, but none of the bars are sorted by size. Maybe it's just not possible.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2014 10:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145751#M40653</guid>
      <dc:creator>ulrich_track</dc:creator>
      <dc:date>2014-10-02T10:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145752#M40654</link>
      <description>&lt;P&gt;What do the column names look like after the &lt;CODE&gt;xyseries&lt;/CODE&gt; in your search? It'll sort the columns lexicographically based on that, which is why I added the number to its front.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2014 20:46:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145752#M40654</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-10-02T20:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145753#M40655</link>
      <description>&lt;P&gt;I was mistaken. Your script does the job: it checks the total occurrence of each sourcetype and then sorts it on the graph in that order. What confused me, was that sometimes a small bar was in between two large bars, but that's correct because only on this index few sourcetypes showed up - looking at all events, it is correct.&lt;/P&gt;

&lt;P&gt;For my script, I adapted it a little in the line &lt;BR /&gt;
    | eventstats sum(count) AS sum BY index&lt;BR /&gt;
but that's fine, the fields have to be adjusted for the individual case.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2014 11:07:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145753#M40655</guid>
      <dc:creator>ulrich_track</dc:creator>
      <dc:date>2014-10-03T11:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort the items within a stacked bar chart by size?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145754#M40656</link>
      <description>&lt;P&gt;Is there a way for not renaming the series?&lt;BR /&gt;
because splunk gives the color basing on the name and I have other charts and the with the same series and i would like to maintain the same colors. &lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2016 15:26:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-the-items-within-a-stacked-bar-chart-by-size/m-p/145754#M40656</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-12T15:26:38Z</dc:date>
    </item>
  </channel>
</rss>

