How to: Display of the time frame of plotted data?

How can I view the time period of plotted data? Example:


Here I have selected a tag in Grafana. Machine data was recorded. But the machine didn’t run all day. How can I display the running time? The data is in an InfluxDB 2 database. What is the InfluxDB query?

Second question: How can I display the duration of the selected period? So the difference between v.timeRangeStop and v.TimeRangeStart?

Here is my solution:
I do it within the flux syntax:

from(bucket: v.defaultBucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my measurement")
  |> filter(fn: (r) => r["_field"] == "any field that is in the measurement")
  |> filter(fn: (r) => r._value != 0)
  |> aggregateWindow(every: 1s, fn: last, createEmpty: false)
  |> count()

I chose second as unit and Last * as Calculation Function.