How to get Dates on x-axis in Trend Visualization

Hi Grafana Community,

Doing research on this problem for hours now but didn’t find anything that helped me. Looking forward to your responses and advice. Thank you very much!

  • What Grafana version and what operating system are you using?
    Grafana v11.0.0 via Docker and Microsoft Windows [Version 10.0.22621.3737]
    Using InfluxDB as a database also via Docker

  • What are you trying to achieve?
    First of all I want to build a simplified visualization of the graph below. Currently I just want the dates on the X-axis and on the y-axis I want to display the developement of tests that have the status passed as line graph (green one). To have an x-axis that is not time I think I need to take “trend” as my visualization in grafana. To have data on the x-axis in the “trend” visualization, an increasing numeric value is required. If I insert the dates as strings it is not possible to have them on the x-axis as there are no increasing numeric value. I have also tried to insert the dates as unix time stamps but then they are also displayed in this format, which is not looking good. But I want to have 4/30/2024, 5/2/2024 etc on the x-axis. Is there a possibility to transform/ override the unix timestamps back into the MM-DD-YYYY format? Or do you know other visualizations or tips to get this sort of graph?

*How are you trying to achieve it?
At the moment I am using the python script below to write my datapoints to an InfluxDB that is connected with Grafana. Also not quite sure if the way I insert the Data is correct to do the queries I need to get the given graph. Open for any advice on data insertion and queries.

import os
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

Connection to InfluxDB

token = “My_InfluxDB_Token”
org = “Tester”
bucket = “trend”
url = “http://localhost:8086
client = InfluxDBClient(url=url, token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)

now = datetime.utcnow()

planned_test_execute_date = int(datetime(2024, 7, 1).timestamp())
actual_test_execute_date = int(datetime(2024, 7, 1).timestamp())

point = Point(“History”)
.tag(“status”, “passed”)
.tag(“TestcaseID”, “1”)
.field(“Planned Test execute Date”, planned_test_execute_date)
.field(“Actual test execute Date”, actual_test_execute_date)
.time(now, WritePrecision.S)

write_api.write(bucket=bucket, org=org, record=point)
print(“Einzelner Datenpunkt wurde erfolgreich in die InfluxDB geschrieben.”)

Can you drop a table view of your data?

1 Like



I inserted actual Date with the UNIX time stamp as a tag & field to then use Group by acutal date in my query. This was my script:

actual_test_execute_date = int(datetime(2024, 4, 25).timestamp())

point = Point(“History”)
.tag(“status”, “passed”)
.tag(“TestcaseID”, “4”)
.tag(“Actual test execute Date”, actual_test_execute_date)
.field(“Planned Test execute Date”, “4/25/2024”)
.field(“Actual test execute Date”, actual_test_execute_date)
.time(now, WritePrecision.S)

This is how my Visualization looks at the moment:

ActualIy I want the amount of test at the y-axis but with the query below the bars are not aligned with the dates on the x-axis.