Click here to Skip to main content
13,731,142 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.4K views
4 bookmarked
Posted 7 Jun 2018
Licenced CPOL

Generating a Pie Chart with Grafana and MS SQL

, 7 Jun 2018
Rate this:
Please Sign up or sign in to vote.
How to generate a pie chart with Grafana and MS SQL

I struggled with this, hope it helps someone.

In Grafana, if we base a visualization on an MS SQL query, and if we set Format as to Time series, for use in Graph panel for example, then the query must return a column named time.

This can make life difficult if we need to generate a chart, for example a Pie Chart, where we don't have a need for the time-visualization as with a bar-chart, for example.

A way around this is to return an aggregate 'time' column, like in the below:

SELECT sum(exceptionCounts.hasException), exceptionCounts.title as metric, _
       count(exceptionCounts.time) as time
FROM
(
SELECT sessionnumber, 
        operationResult, 
        startdatetime as time
  FROM  foobarDatabase.dbo.fullSessionLog
  where operationResult like '%xception%' 
    AND $__timeFilter(customDateTimeStamp)
  group by sessionnumber, operationResult
) as exceptionCounts
group by exceptionCounts.title

In the above, we execute an inner query, which returns a timestamp. In the outer query we can then aggregate - 'count' - the timestamp. And the Pie Chart should work.

It took me some time to figure that one out. Hope it helps!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

harleydk
Denmark Denmark
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 7 Jun 2018
Article Copyright 2018 by harleydk
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid