Creating Stacked Bar Charts on Grafana using data from SQL Server


During a particular day, I have data from multiple categories say A,B,C. I want to create a bar chart in which for every day there is a single bar with different colors for the different categories. The count of categories should be stacked in a single bar for a particular day. I am not able to figure that out in Grafana. Can someone please help me out?

Could you please share the queries and options you’ve tried so far. Maybe a screenshot of what you’re trying to accomplish would greatly help.


You can select Tab Display => Draw options => Select to Stack



That’s not super helpful since you’re using InfluxDB and the topic is regarding Microsoft SQL Server.

Sorry @mefraimsson
But I think datasource not important in this case.
I think this case only config in Display Tab and issue resovle.

1 Like

As I understood it he needs help with how to write the sql query to support his use case and that’s why I did think you’re answer was a bit out of scope - but you’re right it shows how to configure the graph panel to display according to his use case.

@adsingh A query like this should be able to solve it:

  $__timeGroup(<your time column>, '24h') as time,
  <category column> as metric,
  count(<id column?>)
  $__timeFilter(<your time column>)
  $__timeGroup(<your time column>, '24h'),
  <category column>
1 Like

Perfect @mefraimsson. This worked

Hi , i have exactly the same problem . i have all of my data category in one bar , i need them in different bars separated

from each other then i can compare them visually. i need a solution. many thanks

@mefraimsson Do you know how to get rid of the time data on the X-axis of the graph? I have this at the moment and I’d like to only see the date of the day, such as 4/1 instead of having a time next to it.


In your query interval is 24h I want to do it for 1 Month for that I used 1M but it gives error like error parsing interval ‘1M’.

can you help?

try 1m (use lower case like h is in lower case)

It wont help coz I need to group it by one month and not one minute.

excellent. worked it for me , Thank you :slight_smile:

Hi Team

We are trying to create stacked bar chart through
[Apr21] ,
[May21] ,
[Aug21] ,
[Sep21] ,
[Oct21] ,
[Nov21] ,
[Jan22] ,
[Feb22] ,

This Above Fileds we can use
but we didnt get stacked bar s for all months
Can you please let me know solution for thiss

Thanks & Regards

hello everyone
can we create stack bar chart for MS SQL if i don’t have any time based column