Dashboards & Visualizations

How to create a stacked horizontal or vertical bar chart in Splunk?

varma364
Path Finder

Hi All,

I’m trying to create a stacked Vertical bar chart in Splunk, where each bar represents a unique field (e.g., SWC), and the bar is segmented into multiple colors based on a specific status field (e.g., RAG_Status with values Green, Amber, and Red).

Here’s what I’m trying to achieve:

• Each horizontal bar corresponds to a unique SWC.

• The bar is segmented based on the RAG_Status (e.g., Green, Amber, Red).

• The length of each segment represents the count of records for that combination.

• I want the segments to be stacked within the bar, with distinct colors for Green, Amber, and Red.

Sample Query:

 

| inputlookup example_data.csv
| eval RAG_Status = case(
KPI_Score >= KPI_Threshold, "Green",
KPI_Score >= (KPI_Threshold - 5), "Amber",
KPI_Score < (KPI_Threshold - 5), "Red"
)
| chart count BY SWC RAG_Status
| sort SWC

 

Visualization Requirements:

1. Chart Type: Vertical Bar Chart.

2. Stacked Mode: Each bar should show Green, Amber, and Red segments stacked horizontally.

3. Color Scheme:

• Green: #28a745

• Amber: #ffc107

• Red: #dc3545.

Screenshot for Reference:

varma364_0-1733861886371.png

The above is an example of horizontal but I am looking for vertical. 

Current Issue:

I’m unable to configure the Splunk visualization settings or XML code to properly display this data as a Vertical stacked bar chart. Either the entire bar shows as one solid color, or the segments are not stacking as expected.

Any guidance or sample XML code to achieve this would be greatly appreciated!

Current XML code:- 

 

<dashboard version="1.1" theme="light">
  <label>SWC KPI Performance and RAG Distribution_new</label>
  <row>
    <panel>
      <title>RAG Status Distribution by SWC</title>
      <chart>
        <search>
          <query>| inputlookup example_data.csv
| eval RAG_Status = case(
KPI_Score >= KPI_Threshold, "Green",
KPI_Score >= (KPI_Threshold - 5), "Amber",
KPI_Score < (KPI_Threshold - 5), "Red"
)
| chart count BY SWC RAG_Status
| sort SWC</query>
          <earliest>@d</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
       <option name="charting.chart">column</option>
<option name="charting.chart.stackMode">stacked</option>
<option name="charting.seriesColors">#28a745,#ffc107,#dc3545</option>
<option name="charting.legend.placement">right</option>
<option name="charting.axisTitleX.text">SWC</option>
<option name="charting.axisTitleY.text">count</option>
</chart>
    </panel>
  </row>
</dashboard>

 

Current situation:- 

varma364_1-1733862150031.png

Thanks in advance!

Labels (5)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

The fact that you have Rag_Status and count in your legend would indicate you have done a stats count, not a chart count.

See the difference of the tabled output between using this

| makeresults count=200
| eval KPI_Score=random() % 100, KPI_Threshold=80, SWC="SWC:".(random() % 5)
| eval RAG_Status = case(
KPI_Score >= KPI_Threshold, "Green",
KPI_Score >= (KPI_Threshold - 5), "Amber",
KPI_Score < (KPI_Threshold - 5), "Red"
)
| chart count BY SWC RAG_Status
| sort SWC

and then using stats rather than chart in the second line.

In the chart case, you should end up with columns SWC and then Amber, Green and Red, but if you use stats, you will get SWS, RAG_Status and count. In the first case you can stack the data perfectly OK

bowesmana_0-1733961420034.png

 

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The fact that you have Rag_Status and count in your legend would indicate you have done a stats count, not a chart count.

See the difference of the tabled output between using this

| makeresults count=200
| eval KPI_Score=random() % 100, KPI_Threshold=80, SWC="SWC:".(random() % 5)
| eval RAG_Status = case(
KPI_Score >= KPI_Threshold, "Green",
KPI_Score >= (KPI_Threshold - 5), "Amber",
KPI_Score < (KPI_Threshold - 5), "Red"
)
| chart count BY SWC RAG_Status
| sort SWC

and then using stats rather than chart in the second line.

In the chart case, you should end up with columns SWC and then Amber, Green and Red, but if you use stats, you will get SWS, RAG_Status and count. In the first case you can stack the data perfectly OK

bowesmana_0-1733961420034.png

 

0 Karma

varma364
Path Finder

Yes, thank you @bowesmana 

0 Karma

PickleRick
SplunkTrust
SplunkTrust
<dashboard version="1.1" theme="dark">
  <label>vertical_stacked_chart</label>
  <row>
    <panel>
      <chart>
        <search>
          <query>| makeresults format=csv data="a,b,c,d
a,1,2,3
b,2,3,4
c,1,3,4"</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="charting.axisLabelsX.majorLabelStyle.overflowMode">ellipsisNone</option>
        <option name="charting.axisLabelsX.majorLabelStyle.rotation">0</option>
        <option name="charting.axisTitleX.visibility">visible</option>
        <option name="charting.axisTitleY.visibility">visible</option>
        <option name="charting.axisTitleY2.visibility">visible</option>
        <option name="charting.axisX.abbreviation">none</option>
        <option name="charting.axisX.scale">linear</option>
        <option name="charting.axisY.abbreviation">none</option>
        <option name="charting.axisY.scale">linear</option>
        <option name="charting.axisY2.abbreviation">none</option>
        <option name="charting.axisY2.enabled">0</option>
        <option name="charting.axisY2.scale">inherit</option>
        <option name="charting.chart">bar</option>
        <option name="charting.chart.bubbleMaximumSize">50</option>
        <option name="charting.chart.bubbleMinimumSize">10</option>
        <option name="charting.chart.bubbleSizeBy">area</option>
        <option name="charting.chart.nullValueMode">gaps</option>
        <option name="charting.chart.showDataLabels">none</option>
        <option name="charting.chart.sliceCollapsingThreshold">0.01</option>
        <option name="charting.chart.stackMode">stacked</option>
        <option name="charting.chart.style">shiny</option>
        <option name="charting.drilldown">none</option>
        <option name="charting.layout.splitSeries">0</option>
        <option name="charting.layout.splitSeries.allowIndependentYRanges">0</option>
        <option name="charting.legend.labelStyle.overflowMode">ellipsisMiddle</option>
        <option name="charting.legend.mode">standard</option>
        <option name="charting.legend.placement">right</option>
        <option name="charting.lineWidth">2</option>
        <option name="trellis.enabled">0</option>
        <option name="trellis.scales.shared">1</option>
        <option name="trellis.size">medium</option>
      </chart>
    </panel>
  </row>
</dashboard>
0 Karma

varma364
Path Finder

Thanks for the response @PickleRick , I have copied the charting options to my html and still see single line as below. Although when I copied the fill code as a new panel it is working as expected. Do I need to change anything to make the charting options work for my search ?

varma364_1-1733864358791.png

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Honestly, I have no idea. I just did a search, chose visualization, switched to stacked and did "save as" and chose "new dashboard". 😁

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...