I’m fairly new to grafana and I’m currently working on a project where we want to display information from machines in a factory in a grafana dashboard. A feature we want to use is that there is a graph in the dashboard that shows various data within an order that the machine is currently working on. How it works:
- We use the data source Microsoft SQL server.
- We look at the order number of the last written record in the table of a particular machine.
- Based on the previously searched order number, all data is retrieved from the machine that contains the relevant order number.
- This data will appear in a graph.
The problem we now have is as follows: We want all data points within the relevant order to be shown in the chart used. However, what we now see are only the data points that fall within the time range selected at the top of the dashboard. This time range is always fixed on a certain previously set time. We want this time range to be set automatically timefrom: (order start time) timeto: now.
Because all orders have a different start time, the timefrom variable must be dynamic and not fixed. Earlier forms seem to show that this is not possible.
I tried several things and something I found is the following: GitHub - WilliamVenner/grafana-timepicker-buttons: Datasource-configured buttons panel plugin which set the time range of your Grafana dashboard 53. In this panel the times are adjusted when you click on the button of this panel. The code I used in this panel are as followed:
MIN(Time_current) AS ‘time_from’, --selects lowest timestamp within order
‘TijdsInterval’ AS ‘Naam’
Order_Nummer = (SELECT Order_Nummer FROM [Machine] WHERE ID = (SELECT MAX(ID) FROM [Machine]))
This works fine, but the problem is that the time is only adjusted when the button of this panel is clicked. Is there by any chance a possibility to write a piece of code somewhere that automatically selects this button every time the dashboard is refreshed?