Hi everyone,
I hope you’re doing well.
I’m currently using Grafana for a project and facing a challenge that I couldn’t resolve after reviewing the tutorials, forums, and documentation.
Here’s the situation:
- I’m using the Infinity plugin to fetch data from a device, which sends a value data point every minute.
- My goal is to calculate the difference between consecutive data points (i.e., the current value minus the previous value) and display it directly on the graph.
So far, I haven’t found a built-in feature or transformation in Grafana that supports row-level calculations like this.
Has anyone dealt with a similar scenario? Is there a native feature, transformation, or a specific method/plugin to achieve this? Any tips or guidance would be greatly appreciated.
You can do this in infinity by writing some JSONata.
Say if you have data something like
{
"data": [
{ "date": "2024-12-01", "value": 20000 },
{ "date": "2024-12-02", "value": 30200 },
{ "date": "2024-12-03", "value": 42000 },
{ "date": "2024-12-04", "value": 35000 },
{ "date": "2024-12-05", "value": 43000 }
]
}
and you want diffence between previous day / previous data point then the JSONata looks like this
$map($.data,function($v,$index){
return {
"date": $v.date,
"value": $index =0 ? null : $$.data[$index].value - $$.data[$index -1].value
}
})
and then you get…
You can see this in action here
You can apply the same principles to your data. ( You may need to adjust your JSONata query based on data structure. )
Hello,
Thank you for your response and guidance.
When I use $.data
, it displays the data correctly. However, when I try to use return
and $map
functions, I don’t get any output at all.
Could you please guide me on what might be causing this issue or suggest any troubleshooting steps?
Thank you so much for your time and support.
If you can post the actual json and your expected output, community can serve you better.
Or you can always jsonata docs as well
jsonata in one line and dont use double quotes but use single quotes instead.