Grafana图表绘制正常但光标显示数值异常,是否为SQL查询问题?
Hey there! Let's break down why you're seeing those confusing 0 values in your Grafana tooltip, even though the chart itself looks correct at first glance.
First, Fix the Query Typo (Most Likely Culprit)
Looking at your table structure, the field for the meter type is mType_id_mtype, but your query uses mtype_id_type = 22—that's a field name mismatch!
This mistake means your type filter is targeting a non-existent column. MySQL treats this condition as NULL for all rows, so your query might be returning all rows where meter_id_meter = 1—including any hidden rows with m_value = 0 you didn't intend to include. Those extra 0-value entries are exactly what's popping up in your tooltip.
Update your query to use the correct field name:
SELECT time_stamp AS "time", m_value FROM menergy WHERE meter_id_meter = 1 AND mType_id_mtype = 22 ORDER BY time_stamp
If the Query is Correct, Adjust Grafana Visualization Settings
If fixing the field name doesn't resolve the issue, the problem lies in how Grafana handles gaps between your monthly data points:
Check Null Value Handling
- Open your panel's settings (right-side panel)
- Go to the Visualization tab
- Look for the Null value handling option
- If it's set to "As zero", switch it to "Connected" or "Null"—this stops Grafana from filling empty gaps between your data points with 0s.
Disable Tooltip Interpolation
- Still in the Visualization settings, find the Tooltip section
- If "Interpolate values" is turned on, try disabling it. When enabled, Grafana calculates estimated values between your actual data points, which can lead to unexpected 0s over large time gaps.
Verify Raw Query Results
To confirm which issue you're dealing with, switch the query result view in Grafana from "Graph" to "Table". This lets you see every row returned by your query:
- If you spot unexpected 0-value rows, the query typo is definitely the problem.
- If all rows have the correct
m_value, focus on tweaking the Grafana visualization settings.
内容的提问来源于stack exchange,提问作者Alfy14

