Stacked Bar Chart from Table Values

I have some MS SQL data that looks like this (after aggregations):

time       metric Revenue    Cost       Profit
1569909600 Sub1   177.345600 159.611040 17.734560
1569909600 Sub2   187.166900 168.450210 18.716690
1569909600 Sub3   209.718500 188.746650 20.971850

and I’m trying to get a stacked bar chart that looks similar to this:

chart001

I’m having a hell of a time figuring out any way to do it. Any chance someone could help me out? So far the best I can get is all of the bars lined up next to each other:

Ah, it looks like I just can’t stack series data. Found the popular 3-year-old github issue:

I agree with the commentators there that this seems like a no-brainer feature to implement (stacking series data by metric) and am quite surprised no support has been added for it in the 3 years since that issue was opened.

Looks like this plugin might work for me:

1 Like

Hi jceddy, I am trying to run a query for this visualization(grouped bar chart) but some how it is now processing all the values. Eg My query o/p on work bench is fine but I am getting lesser data on grafana. I am attaching my code and o/p screenshots. Please guide me.
Thanks in advance.

1 Like

Hey,

I’m using Grafana 8.2.5, have installed this plugin in my Grafana’s plugin directory after that I have restarted the Grafana Server but still plugin is not visible on console.

Please help me out.

Thanks in advance

With Grafana 8.0 and up, I do not think you need the plug-in. You should be able to do this without any plugins.

Is it possible by writing a SQL queries like grouping, joining etc?

Because I’am doing by creating a SQL queries. It’s not giving the desired stacked bar chart.

It should be. We use MSSQL queries to make the Pie charts, and the logic to make Bar charts should be the same.

Can you post your query text here and the results you get (in SSMS and Grafana)?

Could you share the method you applied to make this chart?
thank you :pray:
I stuck in this problem with the stacked look for so long…

Hi, Am looking to create a stacked horizontal bar chart for non-time series data in grafana Similar to below


Not sure what are the options in grafana ? Any help is apprecaited.

Hi, Even Am looking to create a stacked horizontal bar chart for non-time series data in grafana Similar to below


Not sure what are the options in grafana ? Any help is apprecaited.
Where you able to find the solution ?

this is the example: Grafana
just edit it and change Stacking to Normal

according document about bar chart https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/, stacking bar chart is a grouped bars.

Only one data frame is supported and it must have at least one string field that will be used as the category for an X or Y axis and one or more numerical fields.


If you have more than one numerical field the panel will show grouped bars.

what is means the data format is

Browser stack-frame-1 stack-frame-2 stack-frame-3
Chrome 50 30 40
IE 17.5 27.5 37.5

I am using AWS Athena data source. Just group by a, b won’t create a stacked bar chart. You need 1 column as string and 2 or more columns for numbers. You can use count_if or CASE WHEN to count the number for second dimension. I don’t know whether there is a better solution. If there are a lot of unique values for the dimension, you have to create many columns,e.g.

select os, 
           count_if(platform='amd64') as amd, 
           count_if(platform='arm64') as arm 
from cte group by os