Multiple metrics for Bar Charts


#1

As a newcomer to Grafana, I’m really surprised that the bar charts do not support multiple metrics for the same time period…

It’s a fundamental charting function, and the support for this is gathering momentum in this open issue, which was raised 4 years ago.


#2

Check out multistat, a newly released panel for table queries. Depending on your data, specifically, if you have each value in a separate row - this might work for you.

If your data shows as multiple values per row - send me a copy of your data (CSV format preferred) and I’ll look into adding support for it in the next update.


#3

Hi Michael, I’m a new user - so please be gentle!
My goal is to be able to display a bar chart which compares ‘Solar’ generated energy, against ‘Usage’ energy per day, over a 7 day period. So 2 bars per day, one called Solar, one called Usage.

My metrics are;

metrics

…and I get;

  1. How can I display both metrics per day? I seem to be only able to set one.
    The Label col is set to time, and the Value col is set to Usage, but I can’t add Solar.
  2. The time scale is showing the epoch, instead of the date, which I don’t seem able to change.

Regards

Paul


#4

Interesting. I’m not sure if this will be workable for you, but let’s look anyway.
It looks to me that you are using the time field as the ‘label column’ - this is clever, generating one bar per day - something I’ve not thought of doing before. Trouble is, as you noted, the value of the label field gets printed as-is, in this case, as a huge number. Not good.

I wonder if you can transform the data in the query. I don’t recognize the query editor you are using - is this influxDB? Whatever, I wonder if you cant transform the time value into something printable first and then apply the group operator. I mostly use SQL and CSV data so I’m not sure what your query language supports. The trick is to get it into a table format where the contents are formatted in a way you can display. Something like YYYY-MM-DD (this would be a good choice as it sorts properly too).

As you noted, Multistat currently only displays a single quantity for each bar - this is something I’m thinking of addressing some time soon-ish. But not right away.

I have an idea that might work, if you are willing to try thinking outside the box.

see if you can write the query to return the two values in separate rows (again, I don’t know if your query editor will support this, but in SQL this might use a UNION operator.

Turn something like

date solar usage

2019-02-28 1234 2345

2019-03-01 1111 2222

2019-03-02 1212 2323

into

date valuetype value

2019-02-28 solar 1234

2019-02-28 usage 2345

2019-03-01 solar 1111

2019-03-01 usage 2222

2019-03-02 solar 1212

2019-03-02 usage 2323

Then use ‘date’ as the label column, ‘value’ as the value column and valuetype as the ‘group column’

This should create two bar charts, one for the solar values and one for the usage values. It’s not quite what you are looking for, but it’s a start.

Good luck and send me some data sets in the original two value column formats to play with while I think about adding multi-column support out of the box in a future release.


#5

Thanks for your reply, but unsure how to send you data sets in the original two value column formats…


#6

No problem - I won’t be in a position to do anything on this for another couple of weeks at the earliest anyway. I don’t know if I mentioned this before, but I moved from the US to Switzerland a couple of days and have to manage without regular internet access for a while, which in this business is a bit of a handicap.

Regarding your data set, try opening the panel editor and in the data query section, open the Query analyser, select expand all and copy the result to the clipboard. Then past it all into an email and send it to me. I can use this as an example to work on when I get the chance.


#7

Thanks Michael, I’ve PM’d you with that data (didn’t know your email address)

Paul


#8

perfect - something to work on when I’m back on-line.

Until then…you’re on your own :slight_smile: