Grafana version = 10.1.2
Operating system = Windows 11
I have an MQTT data source where each measurement contains a data sample (float) and a timestamp integer (unix_ms) called “t_measurement”
A time field, called “Time”, is automatically appended to each record received by the MQTT datasource - set to the time the data was received by Grafana.
If I then plot the data in a time series graph, the x-axis uses the automated “Time” field.
How can I change the plot so that “t_measurement” is used for the x-axis instead of “Time”?
Thanks,
Dave
I’m running into the same problem. Have you found a solution?
what does your query look like?
This is the data that is published to the MQTT topic:
{“cityId”:0,“producerId”:0,“producedPower”:84621.59601589036,“timestamp”:1718010000746}
I can convert timestamp to a time unit in Grafana, and it will determine the correct time ranges for which there is data. However, when I try to display them, then it says that there is no data. The query inspector shows 0 rows.
Instead, I can only visualize data in the time range that is provided by the Time field generated by the MQTT source.
{
"cityId":0,
"producerId":0,
"producedPower":84621.59601589036,
"timestamp":1718010000746}
Which of these data points do you want to plot.
I want to have timestamp on the x axis and producedPower on the y axis.
Hi, thanks for the reply but it doesn’t work.
- The MQTT data source automatically extracts the JSON fields. So the first step is not necessary; in fact, if I activate it, there is no data.
- The MQTT data source also automatically adds a Time field to every event.
I want to not use the automatically generated Time field for the x axis but the converted timestamp field.
E.g., in the screenshots below, the timestamp field is converted to the Time type. However, if I remove the Time field from the Filter transformation and rename the timestamp field to Time, no data is shown.
The first screenshot shows the transformation of the data.
The second screen shots shows that Grafana realizes that the time range is now in the future, based on the values in the original timestamp field.
The third screenshot shows what happens when you click on the Zoom to data button. No data is displayed.
1 Like
Hi @viktorrosenfeld,
I am also working on a similar problem, where my sensor is publishing data to MQTT broker and I have configured Telegraf to publish data to InfluxDB.
Sensor → MQTT Broker → Telegraf → InfluxDB_v2 → Grafana
Similarly, I would like to use the timestamp of the event as X-axis for the time graph rather than MQTT Publish Time (auto-selected).
This is how my sample sensor data in JSON format looks like:
{
"name": "my_sensor",
"tag": "timeout",
"downtime": [
{
"timestamp": 1723823532,
"value": 1
}
]
}
Have you found out if it possible to use custom timestamp as x-axis in Grafana?
Cheers, N. T.
Hi,
I gave up on that.
There is the Trend visualization (description: like time series, but when x != time), but it’s beta and I could not get it working reliably.
Good luck!
Viktor