Grafana - Bar Chart with Multiple Series | How To Tutorial Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi so i have a graffana bar chart here with multiple series and i've been looking for actually documentation on how to do this and it was not very straightforward so for example on the graphana documentation this is really all you get and it's not very helpful so i imagine if you're here that's probably what you found also so let me go ahead and show you here that you know this grafana bar chart has multiple series as you can see and on the axis here there is the months from 1 through 12 but also down at the bottom here and on the bars here you can see the series the series are by year 2011 2012 2013 2014 and if i hover over it you can see that there's the values of the particular bar for that particular year so let me go ahead and show you how this is actually done now graffana and that particular bar chart component actually expects a particular format and the format is actually this type of table here that you see at the bottom so this table is actually the same exact data as the bar chart with multiple series above so let me switch over to uh my sql server here so i am using the sql server database but this would be the same for mysql postgres or any other type of data set you know it doesn't have to be a relational database but that is what i'm using here so you'll notice here at the bottom i have that particular same format that i have at the grafana here and so what you'll see here is the way i was able to format this particular query to look like this now let me go over some of the basics here so i have some mock sales data here and this is the particular table format so let me show you the first 10 rows here of just very standard data there is a date here that i'm going to base my sales date on and then there is this table that i am going to query against now normally if you wanted to know the monthly sales broken by year you would have an aggregate function that counts the particular rows grouped by that particular year and month and the data and the query is very basic here and the data would look like the following so the data would kind of look like this so this is basically a very kind of basic query that what we're all very used to things are grouped by basically year month and that is the total of the number of rows and that equates to the number of sales in that particular month now i have to create a what you would call transpose these rows into columns or another word for that is to pivot this data into a pivot table so if i show you that particular pivot table it's the format that that particular graphana bar chart component expects so here you'll see the columns and these columns are the series and this is the access and this particular data is the data for each particular bar so what i will show you here side by side the two queries the query that we're usually pretty familiar with at the top here so you could see 2011 month 5 357 is the total number sales and the same data represented in a pivot table or transposed is month five year 2011 is 357 and if i scroll all the way down just to give you an exam another example 2014 month 6 is 2030 and that's where this 2030 comes from now if i copy and paste this entire query here and let me just show you that entire query is just the same query there let me show you that in the edit you'll see that this is the exact same query now what i have to do here is um just basically paste the query but i also have to format change the format so normally it defaults to time series and you'll notice here that it's not populating so i have to switch it over to the table and sometimes this doesn't populate in which case you will click on the generate quick sql and then it'll populate the graph here but the other thing i have to do is not only change the format as to table i have to go up here to the bar chart usually it defaults to time series and so it's not going to show that the time series expects a particular field named time i'm not using that i'm using the bar chart so i'm going to switch over the bar chart and it'll show up here now the other thing you could do is also just basically change the palette so here you have a color scheme here it's the classic palette that i've chosen but you could choose multiple color schemes or just even a solid color if you wanted to i'm going to change back to the classic pattern here so that is basically how you do the multiple series by formatting the data in the way that the chart component expects now if you don't format the data from the query itself you're going to have to transform it basically manually here using these fields but i think it's actually easier simply to write the query and transform the data in the format that it expects so so just going back to this documentation here nothing in this documentation will explain that to you what i've just explained the other thing i also want to show is just going back to this panel so if i go back to this panel here what you will see is that the bottom here i actually have the table and that particular table is actually the same exact data that i have at the top here so for example if i edit this particular table you could see it's simply the format is simply the same it's table but here i've chosen table so if i choose bar chart it'll just end up being this and if i scroll all the way back down as i shown before with the palette the color scheme it comes back to this but if i choose table i will get this particular table so i'm just going to click apply here and go back so i want to format this here and show that table alongside the actual data of the bar chart itself so that's really it that is actually the secret sauce to how you do multiple series using this bar chart um and that's really what i want to go through now i'm going to have other tutorials on how to do the time series and how to do multiple series on the basically line graphs and stuff like that so uh stay tuned for those videos if this video was helpful definitely support this channel by thumbs up the channel and also subscribing and thank you so much for watching and have a great day thank you you
Info
Channel: CodeCowboyOrg
Views: 35,304
Rating: undefined out of 5
Keywords:
Id: ky78RZ2f7oc
Channel Id: undefined
Length: 8min 12sec (492 seconds)
Published: Sun Jan 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.