Weird lines connections in the Graph

I have a panel with Graph visualization.

The data source is PostgreSQL and here’s the SQL query:

SELECT
  $__time(dt),
  items
FROM results
WHERE
  $__timeFilter(dt)

The problem is that certain timespans/timefilter ranges result in weird visualizations like this:

Here are the values for this particular query:

2020-06-04T12:54:50Z - 6
2020-06-04T12:54:32Z - 10
2020-06-04T11:47:23Z - 161
2020-06-04T11:38:48Z - 131
2020-06-04T11:35:26Z - 79
2020-06-04T11:34:30Z - 5
2020-06-04T11:33:15Z - 6
2020-06-04T11:23:42Z - 6
2020-06-04T11:23:18Z - 9
2020-06-03T20:47:09Z - 160
2020-06-03T20:47:07Z - 397
2020-06-03T20:42:07Z - 110

I don’t understand why the data point with the value 397 has this weird connection? Based on the data, it “lives” in 03 day, so why is it not connected to other points from 03 day, and instead is connected to points from the next (04) day?

My understanding is that it should be something like this:

Am I missing something about the way Graph connects data points with lines?

Here's the full panel JSON just in case
{
  "aliasColors": {},
  "dashLength": 10,
  "fill": 1,
  "gridPos": {
    "h": 9,
    "w": 12,
    "x": 0,
    "y": 9
  },
  "id": 4,
  "legend": {
    "alignAsTable": false,
    "avg": false,
    "current": true,
    "max": false,
    "min": false,
    "show": true,
    "total": false,
    "values": true,
    "hideEmpty": false,
    "hideZero": false
  },
  "linewidth": 1,
  "nullPointMode": "null",
  "options": {
    "dataLinks": []
  },
  "pointradius": 3,
  "points": true,
  "renderer": "flot",
  "seriesOverrides": [],
  "spaceLength": 10,
  "targets": [
    {
      "format": "time_series",
      "group": [],
      "metricColumn": "none",
      "rawQuery": true,
      "rawSql": "SELECT\n  $__time(dt),\n  items\nFROM results\nWHERE\n  $__timeFilter(dt)",
      "refId": "A",
      "select": [
        [
          {
            "params": [
              "value"
            ],
            "type": "column"
          }
        ]
      ],
      "timeColumn": "time",
      "where": [
        {
          "name": "$__timeFilter",
          "params": [],
          "type": "macro"
        }
      ]
    }
  ],
  "thresholds": [],
  "timeRegions": [],
  "title": "slug/ttf_to_slug.json | FPS",
  "tooltip": {
    "shared": false,
    "sort": 0,
    "value_type": "individual"
  },
  "type": "graph",
  "xaxis": {
    "buckets": null,
    "mode": "time",
    "name": null,
    "show": true,
    "values": []
  },
  "yaxes": [
    {
      "$$hashKey": "object:376",
      "format": "none",
      "label": null,
      "logBase": 1,
      "max": null,
      "min": null,
      "show": true
    },
    {
      "$$hashKey": "object:377",
      "format": "short",
      "label": null,
      "logBase": 1,
      "max": null,
      "min": null,
      "show": false
    }
  ],
  "yaxis": {
    "align": false,
    "alignLevel": null
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": null
      },
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "value": null,
            "color": "green"
          },
          {
            "value": 80,
            "color": "red"
          }
        ]
      },
      "mappings": []
    },
    "overrides": []
  },
  "pluginVersion": "7.0.3",
  "links": [],
  "maxDataPoints": 3,
  "lines": true,
  "timeFrom": null,
  "timeShift": null,
  "interval": null,
  "cacheTimeout": null,
  "bars": false,
  "dashes": false,
  "fillGradient": 0,
  "hiddenSeries": false,
  "percentage": false,
  "stack": false,
  "steppedLine": false,
  "datasource": null
}
$ grafana-server -v
Version 7.0.3 (commit: 00ee734baf, branch: HEAD)

Hello,

I think the points are connected according to their order in the query results. Is it better if you add an order by time in your query?

1 Like

Oh my, I should have guessed.
Missing ORDER BY time seems to be the reason, now it’s all good.
Thank you!