I used the plotly panel plugin, the database table has two fields that are being used here: time, the timestamp for the measurement. ppv_total the watts being produced at that time.
I started off with the same query as for the time series panel:
select to_char(time::date,'YYYY-mm-dd') as parameter,
now()::date+time::time as time,
round(sum(ppv_total/12) over (partition by time::date order by time)) as " "
from pv where pv.time > now()::date - interval '7 days'
order by time;
âselect to_char(time::date,âYYYY-mm-ddâ)â gives me the date of the measurement as text, ânow()::date+time::timeâ moves the measurement to today so I get it all on the same scale. âround(sum(ppv_total/12) over (partition by time::date order by time))â gives the sum produced up to a given time of day. /12 is because I get a number of watt each five minutes and I want to get it to kWh,
So the query will give me a table like
So far so good. For the plotly panel, a bit of coding is needed. For âData of the plotâ, I have
[
{
"line": {
"color": "rgba(255,255,255,255)",
"width": 1
}
}
]
I think this is overridden later on. For Layout, I have quite a good chunk of json:
{
"annotations": [
{
"showarrow": false,
"text": "kWh",
"textangle": -90,
"x": -0.03,
"xanchor": "right",
"xref": "paper",
"y": 0.5,
"yanchor": "right",
"yref": "paper"
}
],
"colorway": "D3",
"font": {
"color": "darkgrey",
"family": "Inter",
"weight": 400
},
"hovermode": "closest",
"legend": {
"entrywidth": 0,
"itemsizing": "constant",
"itemwidth": 8,
"orientation": "h",
"x": 0,
"xanchor": "left",
"y": -0.5,
"yanchor": "middle"
},
"margin": {
"b": 10,
"l": 40,
"r": 10,
"t": 15
},
"paper_bgcolor": "rgba(0,0,0,0)",
"plot_bgcolor": "rgba(0,0,0,0)",
"xaxis": {
"autorange": true,
"color": "#444",
"gridcolor": "#444",
"gridwidth": 1,
"range": [
"2024-06-10 07:20:01",
"2024-06-11 00:15:01"
],
"tickformat": "%H:%M",
"type": "date"
},
"yaxis": {
"autorange": true,
"color": "#444",
"gridcolor": "#344",
"range": [
-0.8240555555555558,
15.677055555555556
],
"type": "linear"
}
}
âConfigurationâ is empty, and then I have some javascript to go from the grafana table to what I want in plotly, âScriptâ:
let dataset = []
let colors = [0,"#2E91E5", "#E15F99", "#1CA71C", "#FB0D0D", "#DA16FF",
"#B68100", "#750D86", "#222A2A","#EB663B"];
for (set =1; set<9; set++){
let x = [];
let y = [];
try{
data.series[0].fields[set].values.forEach(function (item, index) {
if (item > ''){
y.push(item/1000);
x.push(data.series[0].fields[0].values[index]);
}
});
if (set == 8){
line={width:4,
color: "yellow"};
}else{
line={width:2,
color: colors[set]};
}
let serie = {
x : x,
y : y,
name : data.series[0].fields[set].labels.parameter.slice(-5),
line: line
};
dataset.push(serie)
}catch(e){
// missing data
}
}
return {
data : dataset,
config : {
displayModeBar: false
}
}
And in the end âClick Scriptâ is just
window.updateVariables({query:{'var-project':'test'}, partial: true})
It was quite a bit to pull together, but now it is working beautifully, although it does not look like a real grafana graph panel, but not too bad.