Hello everyone!
I am using Grafana 10.0.0
I would like to compare the flowrate value between two different time periods.
As Grafana has only one time picker, I created two variables with the text format in which the user can write the time stamps in the format (yyyymmdd hh:mm).
I realised quickly that even that cannot help as dual x - axis setup is not natively supported in grafana. And when i use only the past time values in the variables, i need to zoom back as the panel states that it is outside range.
I then realised that using plotly could work. But, I am a beginner and not well versed on how to use that.
These are the two sql queries. Both are through stored procedure. First two values are the start and end times. Third is the Data ID and the last one is the time interval in seconds.
Based on native time picker
EXEC LC.db.usData $__timeFrom(), $__timeTo(), ‘1715’, 600;
Based on time variable
EXEC LC.db.usData ‘${Past_st}’,‘${Past_end}’, ‘1715’, 600;
This is how the table view looks like after running the query
This is my current code
For the data panel
[
{
“x”: “TimestampUtc”,
“y”: “DI1715”,
“type”: “scatter”,
“mode”: “lines”,
“name”: “DI1715”
}
]
For the Layout Panel
{
“title”: “Time Series Data for DI1715”,
“xaxis”: {
“title”: “Time”,
“type”: “date”
},
“yaxis”: {
“title”: “DI1715 Value”
}
}
For the configuaration panel
{
“responsive”: true,
“displayModeBar”: true
}
For the Script panel
let timestamps = data.series[0].fields.find(field => field.name === ‘TimestampUtc’).values.buffer;
let values = data.series[0].fields.find(field => field.name === ‘DI1715’).values.buffer;timestamps = timestamps.map(ts => new Date(ts));
let trace = {
x: timestamps,
y: values,
type: ‘scatter’,
mode: ‘lines’,
name: ‘DI1715’
};let layout = {
title: ‘Time Series Data for DI1715’,
xaxis: { title: ‘Time’, type: ‘date’ },
yaxis: { title: ‘DI1715 Value’ }
};return { data: [trace], layout: layout };
For the ClickScript panel
function handleClick(event) {
let point = event.points[0];
alert(Timestamp: ${point.x}, Value: ${point.y}
);
}document.getElementById(‘plotly-div’).on(‘plotly_click’, handleClick);
I tried to find some instructions regarding this. But, I am not able find something that could work for me. Any help would be greatly appreciated.