Splunk Search

Is it possible to customize the order of fields in the legend for a stacked column chart?

splunkrocks2014
Communicator

Hi. I have a stacked column chart with stacked. The end of the search is the following:

 | chart count over fields by status

I think by default, the legend is displayed by alphabetical order based on the status name. Is it possible to customize the order? For instance, I have status with a,b,c,d,and e, can I sort the order as a, c, e, d, b?

Thanks.

Kenshiro70
Path Finder

Use the fields command, like so:

| chart count over serverType by status
| fields serverType a c e d b

(I changed the name from "fields" in the original example to "serverType" to avoid confusion.)

Note that depending on the result set, you might need to use transpose or xyseries to move the data fields into columns.

woodcock
Esteemed Legend

Yes, you need to prepend the appropriate number of spaces to each so that the names will be alphabetically in the order that you desire. When splunk renders the names of each, the spaces will be invisible. So in your case, like this:

| chart count over fields by status | rename a AS "    a" c AS "   c" e AS "  e" d AS " d"

jkat54
SplunkTrust
SplunkTrust

Sure. We typically achieve this with an eval if condition that affixes a number to the front like this.

| eval status=if(status=="a","1.a",if(status=="c","2.c","else"))

You could do this with if or case eval functions and you might need to combine it with the match eval function so you can match based on regex:

 | eval status=if(match(status,"[aA]"),"1.a",if(match(status,"[cC]"),"2.c","else"))

or like this but replacing {regex} with a regex that matches what you're looking for:

 | eval status=if(match(status,"{regex}"),"1.a",if(match(status,"{regex}"),"2.c","else"))

jkat54
SplunkTrust
SplunkTrust

Yep, only method without numbers or letters is custom JS or css or maybe both. Would only work for specific data and I'd only recommend it in narrow circumstances however.

0 Karma

splunkrocks2014
Communicator

That works as expected, but the status name starts with a number. I guess that's impossible to remove the number.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...