Dashboards & Visualizations

How to have different color for each bar in column chart?

vrmandadi
Builder

I am using the following query to get the results 

index=abc node=*
| chart latest(state) as state by node 
| stats count by state 
| sort - state

 

Below is the column chart display of it.I want to display each state by a custom color 

vrmandadi_0-1671215294071.png

 

I tried using the below line in xml but its not changing

<option name="charting.fieldColors">{"Allocated":0x333333,"DOWN":0xd93f3c,"IDLE":0xf58f39,"Minor":0xf7bc38,"Notice"  :0xeeeeee,"Healthy":0x65a637}</option>
Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

fieldcolors option applies to the name of the field in a multi-series chart, not the value of a particular field. In order to do what you're trying to do, you'll have to change your SPL to add the following to the end

 

| eval {state}=count
| fields - count
| table state *

 

That will then make the bar columns be different colours, then you can define fieldcolor settings to the exact strings of the state name. 

Or, you could do something like this, if you want to group "down*", idle and allocated related items together

 

| stats sum(eval(if(match(state, "^DOWN"), 1, 0))) as DOWN sum(eval(if(match(state, "^IDLE"), 1, 0))) as IDLE sum(eval(if(match(state, "^ALLOCATED"), 1, 0))) as Allocated by state

 

 and then you can define your field colours as 

 

<option name="charting.fieldColors">{"Allocated":0x333333,"DOWN":0xd93f3c,"IDLE":0xf58f39,"Minor":0xf7bc38,"Notice"  :0xeeeeee,"Healthy":0x65a637}</option>

 

Although I am not sure what your data looks like for your Minor/Notice/Healthy.

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

fieldcolors option applies to the name of the field in a multi-series chart, not the value of a particular field. In order to do what you're trying to do, you'll have to change your SPL to add the following to the end

 

| eval {state}=count
| fields - count
| table state *

 

That will then make the bar columns be different colours, then you can define fieldcolor settings to the exact strings of the state name. 

Or, you could do something like this, if you want to group "down*", idle and allocated related items together

 

| stats sum(eval(if(match(state, "^DOWN"), 1, 0))) as DOWN sum(eval(if(match(state, "^IDLE"), 1, 0))) as IDLE sum(eval(if(match(state, "^ALLOCATED"), 1, 0))) as Allocated by state

 

 and then you can define your field colours as 

 

<option name="charting.fieldColors">{"Allocated":0x333333,"DOWN":0xd93f3c,"IDLE":0xf58f39,"Minor":0xf7bc38,"Notice"  :0xeeeeee,"Healthy":0x65a637}</option>

 

Although I am not sure what your data looks like for your Minor/Notice/Healthy.

0 Karma

vrmandadi
Builder

Thank you @bowesmana  ..cheers

0 Karma
Get Updates on the Splunk Community!

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...