Hi there, I want to display a graph with mysql as data source, but as series.
In my example, I have a set of people, and the year when they got born. I want to construct a graph now, which shows how often people are born in year x. Currently I tried this via something like:
SELECT year,
COUNT(year)
FROM peoples
WHERE year IS NOT NULL
GROUP BY year;
This leads into a weird situation: Grafana says, “No field name specified to use for x-axis, check your axes settings”, but when this happens, I’m not able to change the X-Axis Mode. Any advice?
Hi
i have below data into MySQL, still get error “No field name specified to use for x-axis, check your axes settings” Unable to select X-Axis Mode
Checked SQL query , it is converting below data into timestamp format. so query looks okay.
Here is the request thats gets generated. I see from & to values which goes from grafana are far too bigger than MySQL UNIX_TIMESTAMP values.
MySQL unix time stamp value = 1532719800
Grafana value (as part of request) = 1535394000000
Is this cause of issue ?
I formulated below query in MySQL based on Grafana request & its returning zero records.
SELECT UNIX_TIMESTAMP(time) as time_sec, Voltage as value, Voltage as metric FROM 24hr_Energy
WHERE time>=convert (1535394000000,datetime) and time <=convert(1535480400000,datetime) ORDER BY time ASC;
Grafana request–>
xhrStatus:“complete”
request:Object
method:“POST”
url:“api/tsdb/query”
data:Object from:"1535394000000" to:"1535480400000"
queries:Array[1]
0:Object
refId:“A”
intervalMs:120000
maxDataPoints:683
datasourceId:2
rawSql:"SELECT UNIX_TIMESTAMP(time) as time_sec, HVAC as value, HVAC as metric FROM 24hr_Energy WHERE $__timeFilter(time) ORDER BY time ASC "
format:“time_series”
This shows a bar chart with the number of open work orders grouped by priority (Urgent, High, Medium, Low)
=======
So I was able to figure this out with the following sql statement:
SELECT UNIX_TIMESTAMP() as time_sec, COUNT(*) as value, P.PRIORITY_TYPE_NAMEas metric FROM JOB_TICKET J, PRIORITY_TYPE P WHERE J.DELETED !=1 AND J.STATUS_TYPE_ID IN (1,2) AND J.PRIORITY_TYPE_ID= P.PRIORITY_TYPE_ID group by J.PRIORITY_TYPE_ID
Time Series
Axes
Left Y show
Unit short
Scale linear
Label Number
select
(select max(time_msg) from message_tx) as time,
SUM(case when provider = ‘prov1’ then 1 else 0 end) as data1,
SUM(case when provider = ‘prov2’ then 1 else 0 end) as data2,
SUM(case when provider = ‘prov3’ then 1 else 0 end) as data3,
SUM(case when provider = ‘prov4’ then 1 else 0 end) as data4,
from
message_tx
where
date_part(‘year’,time_msg) = ‘[[year]]’ and date_part(‘month’,time_msg) = ‘[[month]]’
I mean, I give time variable to the graph, but in X-axis i select series and voilá