How to include Std dev in Legends of time series?

I am new to grafana and I have the latest version (8.4.3). I created a panel using Time Series and I am able to include max, min, mean and so on in the legends. Along with that, I want to include Std dev and how can I do?

welcome to the :grafana: forum, @selvavm

I don’t think standard deviation is a possible legend value in Grafana. That might make a good feature request.

What datasource are you using? You could always try to calculate standard deviation on the DB side. I think influx has a stddev() function…`

Thanks mattabrams. My database supports it but I am not able to find how to do add this to the legend? Is there a way?

you can’t add it to the legend in the same way as the other built-in legend items

Sorry for late response. I met with unfortunate events.

Could you tell me how can I visualise the standard deviation from my db? For example, I can write below queries

select t, events from from pingtable

select min(events), stddev(events) from pingtable

Please provide your sample data as csv as follows and the visualization you want to use?


or basic DDL and DML

create table areas(id nt, report_date datetime, 
area varchar(50), team, char(1), volume int)

insert into areas

Hi below is the details

create table pingtable(hit_date datetime, 
events int, browser char(1))

insert into pingtable
values('2022-04-18','10', 'E');
insert into pingtable
values('2022-04-19','5', 'E');
insert into pingtable
values('2022-04-20','15', 'E');

I would like to plot the timeseries and in legends (or somewhere) see the standard deviation as 4.08.

1 Like

option 1
create a hidden dashboard variable named standarddev with

SELECT  STDEVP(events) as value FROM pingtable

Then for you data source query do

 events as value,
 events metric,
 $standarddev deviation
FROM pingtable 
ORDER BY hit_date ASC

results in (painful on the eyes) with using Legend Mode/Legend Values of Last

option 2 (best option) as it can also scale cleanly with more values.
one time series with gauge or stat (both use sql statement
SELECT STDEVP(events) as value FROM pingtable

Thanks. I have repeating panels to plot different columns based on user selection. If I want to get this, then I believe I will have to change the repeating panels to repeating rows. Am I right?

Also, I could see that a query is hit per panel. So if I have 5 panels, 5 queries are hit. So, in this case, it will be 10 queries per row. Is there a way to optimise the counts of queries.

this sounds like a totally new question unrelated to std dev? If so maybe create a new topic?

thanks. Will do that.