Splunk Search

Show an area under a chart

kvaga
Explorer

I have a line chart and have to calculate area under this chart. The calculated area must be presented on a chart panel or on the chart itself. How can I fo it? I realise that the line is merely set of points tiered together. But it's really must have task for me

0 Karma

efavreau
Motivator

It sounds like you are looking to calculate a definite integral to get the line under a graph. Excel has a similar issue, and the solution here would be similar. Approximate the area underneath the line by creating a series of trapezoids, and calculate the area in each of those trapezoids, then add them altogether. The smaller the width of the trapezoids, the more accurate the estimation will be.

The area of a trapezoid is calculated as: (Sum of 2 vertical sides) / 2 x (Base of trapezoid)

This metric has no units per se, because you aren't dealing with a definitive unit like inches. So when you use this formula, you need to define your units for length of the sides and the base, and keep them consistent every time you use it.

In the run anywhere example dashboard below, I've used 1 second for the base. YMMV due to the size of your data events. I might recommend a dashboard with one query that gets you the line chart visualization in one panel and a separate query that gets you the area as a single value visualization in another panel.

Visualized:
a dashboard panel of a single value above another panel showing a area chart using a related query
Here's the dashboard code:

 <dashboard>
      <label>area under the line</label>
      <row>
        <panel>
          <single>
            <search>
              <query>index=_internal sourcetype="*d_access" OR sourcetype="*d_ui_access" OR sourcetype="*k_web_access" earliest="-1m@m" latest="@m" 
    | bucket _time span=1s 
    | stats count AS "Count" BY _time 
    | eval baseoftrapezoid=1 
    | eval twoxbaseoftrapezoid=2*baseoftrapezoid 
    | autoregress Count p=1 
    | eval vericalsideone=Count 
    | eval vericalsidetwo=Count_p1 
    | eval area=(vericalsideone + vericalsidetwo) / twoxbaseoftrapezoid 
    | eventstats sum(area) AS "TotalArea"
    | table TotalArea</query>
              <earliest>-24h@h</earliest>
              <latest>now</latest>
            </search>
            <option name="drilldown">none</option>
            <option name="underLabel">Area under the line (approx)</option>
            <option name="useThousandSeparators">0</option>
          </single>
        </panel>
      </row>
      <row>
        <panel>
          <chart>
            <search>
              <query>index=_internal sourcetype="*d_access" OR sourcetype="*d_ui_access" OR sourcetype="*k_web_access" earliest="-1m@m" latest="@m" 
    | bucket _time span=1s 
    | stats count AS "Count" BY _time</query>
              <earliest>-24h@h</earliest>
              <latest>now</latest>
            </search>
            <option name="charting.chart">area</option>
            <option name="charting.drilldown">none</option>
          </chart>
        </panel>
      </row>
    </dashboard>
###

If this reply helps you, an upvote would be appreciated.

somesoni2
Revered Legend

What do you mean by calculating area under the line chart? Could you provide some example (with values) of what you expect?

0 Karma

kvaga
Explorer

I want to calculate an area of the red shape area. Please find attached an example: https://yadi.sk/i/stejtyVF8T06CA

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...