Dashboards & Visualizations

Constants in Splunk Bar Graph Charts

asarolkar
Builder

I have a query like this - which charts the number of grapes and pears in a fruit cart

sourcetype="fruitlog" type="pear" OR type="grape" | eval InStock=10 | chart first(InStock) as InStock,count(eval(type="pear")) AS numPears, count(eval(type="grape")) AS numGrapes

The InStock amount is the total number of fruits that is UNRELATED to the number of Pears and Grapes.

When I put this up on a dashboard, NO bar appears for the InStock Value of 10. I see numPears and I see numGrapes.

Any ideas so as to why this CONSTANT value would not display on a chart ? It might sound stupid to even have it there, but I need for it to show for comparison.

0 Karma
1 Solution

jonuwz
Influencer

Add this to the end of your search

 | transpose | rename "row 1" as count

The trick is to get your data in multiple rows, not across multiple columns.

You can also replace 'chart' with 'stats'

A neater search might be

sourcetype="fruitlog" type="pear" OR type="grape"
| stats count by type 
| appendpipe [ head 1 | eval type="InStock" | eval count=10 | fields type count ]

The 1st 2 lines gets the count per type (which will graph as-is)

the last line just spoofs an entry for InStock

View solution in original post

jonuwz
Influencer

Add this to the end of your search

 | transpose | rename "row 1" as count

The trick is to get your data in multiple rows, not across multiple columns.

You can also replace 'chart' with 'stats'

A neater search might be

sourcetype="fruitlog" type="pear" OR type="grape"
| stats count by type 
| appendpipe [ head 1 | eval type="InStock" | eval count=10 | fields type count ]

The 1st 2 lines gets the count per type (which will graph as-is)

the last line just spoofs an entry for InStock

jonuwz
Influencer

yeah - i don't have your data, but this seems to be similar to what you're using :

index=_internal | eval instock=10 | stats first(instock) as instock count(eval(group=="pipeline")) as pipe count(eval(group=="queue")) as queue | transpose | rename "row 1" as count`

or

index=_internal group="pipeline" OR group="queue" | stats count by group | appendpipe [ head 1 | eval group="InStock" | eval count=10 | fields group count ]

asarolkar
Builder

sourcetype="fruitlog" type="pear" OR type="grape" | eval InStock=10 | chart first(InStock) as InStock,count(eval(type="pear")) AS numPears, count(eval(type="grape")) AS numGrapes | transpose | rename "row 1" as count ???

0 Karma

Ayn
Legend

It's not that it's a constant, it's that your search will generate one row with multiple columns and the first column will be the one used by the bar chart for the Y-axis label. Try removing the first part of your chart command and you'll see that numPears will disappear from the bar chart and instead be used as a label.

asarolkar
Builder

So, how would you recommend I frame my search.

A timechart is not desired here but just a chart.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...