Simple Chart Assistance

Hello there, new Grafana user here.

I am hoping to use Grafana to create dashboards from data that is held on a local Postgres database. The Query Editor is working correctly and returning data as I would expect. However, I am struggling to plot this data in a graph.

One of my queries returns a list of items, and their corresponding count. I want the list of items along the x axis, and the count on the y - fairly standard stuff. I have selected ‘Graph’ as the panel type, but it would appear that this only likes to plot things when the x axis contains a time/date value. I have set the X-Axis mode to ‘Series’ as suggested in the docs, but am really struggling to get the graph to work at all.

Query:

SELECT COUNT(items) AS Count, items 
FROM global
GROUP BY items
ORDER BY Count DESC;

Would really appreciate some help as how to get this working!

I am trying to plot a chart using some Time Series data, however, the graph is not plotting as I would expect.

I am doing a count on the time column exclusively, and wanting to plot data per hour. The timestamp is a standard format, e.g., 2017-12-10 05:07:12.

The SQL query I have is:

SELECT observation_date AS time, COUNT(date_trunc('hour', observation_date))
FROM global
GROUP BY time;

However, this is generating a very unusual chart:

I also wondered how I could format the date/time x values in the UK format, namely DD/MM, rather than MM/DD. I have set the unit as locale format, which does not appear to have helped.

This is what I am hoping to plot:

16

Other things I have tried is also wrapping the query with the macro as follows:

SELECT $__time(observation_date)

and also

COUNT(date_trunc('day', observation_date)) AS metric

However these don’t seem to help, with the latter returning a Column metric must be of type char,varchar or text error.

Would really appreciate your help!

You need to add: “SORT BY time”

1 Like