Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Graph does not continue last value to current time #7778

Closed
oblogic7 opened this issue Mar 8, 2017 · 7 comments
Closed

[Bug] Graph does not continue last value to current time #7778

oblogic7 opened this issue Mar 8, 2017 · 7 comments

Comments

@oblogic7
Copy link

oblogic7 commented Mar 8, 2017

Please include this information:

  • What Grafana version are you using?
    4.0.1
  • What datasource are you using?
    InfluxDB
  • What OS are you running grafana on?
    Raspbian Jessie
  • What did you do?
    Created a chart containing data from a sensor that reports a binary state. I used stiarcase display option with line and fill to indicate the state of the data.
  • What was the expected result?
    I expect that this combination of options (staircase + line) will automatically continue the line representing the last reported value to current time.
  • What happened instead?
    The graph does not represent the current state of the sensor since the line does not continue past the last recorded value to current time. This means that if the last recorded datapoint is outside of the current time window, then the visual representation of the data is incorrect.

image

SELECT "value" FROM "binary_sensor.test_door" WHERE time > 1488940908s and time < 1488941178s

{ "results": [ { "statement_id": 0, "series": [ { "name": "binary_sensor.test_door", "columns": [ "time", "value" ], "values": [ [ 1488941015270, 0 ], [ 1488941018852, 1 ], [ 1488941033473, 0 ], [ 1488941047516, 1 ] ] } ] } ] }

@torkelo
Copy link
Member

torkelo commented Mar 9, 2017

Grafana does not invent values as would be required in this case, would be tricky as could be not what the user wants in many cases.

In graphite there is a function keepLast that will make the database query keep last value, should have worked in your case. Think InfluxDB has fill(last) which works the same but not sure.

@torkelo torkelo closed this as completed Mar 9, 2017
@oblogic7
Copy link
Author

oblogic7 commented Mar 9, 2017

The problem with fill(previous) is that it uses group by and requires an aggregate on the select. For a binary state, aggregation of the values via mean() results in improper display of the data at certain zoom levels. It does allow the previous value to continue to current time on the graph, but it means trading one incorrect visual representation for another.

image

I don't expect Grafana to "invent values", but expect it to be smart enough to display the current state of a measurement even if the latest result is not within the currently selected time range.

@torkelo
Copy link
Member

torkelo commented Mar 9, 2017

I don't expect Grafana to "invent values", but expect it to be smart enough to display the current state of a measurement even if the latest result is not within the currently selected time range.

That is the responsibility of the TSDB query language. Graphite can do this for example. Much better to put this logic in the query. No way for Grafana to know that this is desired behaviour other than a a specific option for this. But it's a feature that feels much better placed in the query & transformation layer (TSDB query engine).

requires an aggregate on the select. For a binary state, aggregation of the values via mean() results in improper display of the data at certain zoom levels.

Would not max(value) or last(value) work for your case? I mean there are other aggregations functions than mean :)

@oblogic7
Copy link
Author

oblogic7 commented Mar 9, 2017

Maybe I'm missing something, but I'm not presented with max or last options for aggregations.

image

@torkelo
Copy link
Member

torkelo commented Mar 9, 2017

They are under Selectors (don't blame grafana for the strange categorisation, I took it from InfluxDB docs)

@phemmer
Copy link
Contributor

phemmer commented Aug 27, 2017

For reference, see also #2296, as this issue seems to be a duplicate of that one.

@rb1205
Copy link

rb1205 commented Jun 21, 2023

In case of staircase graphs, this can be easily worked around with manual SQL by returning an extra row with a fixed value in the distant future. This way the graph will continue the line to the right and beyond. The fixed value can be whatever, just use 0.

The way to do this depends on the actual SQL engine, for example for MySQL/MariaDB you can use UNION like this:

(SELECT <actual query>) UNION (SELECT 10000000000000000, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants