Comments (8)
Yes, it's a very common pattern. Fortunately, in recent Grafana versions, renaming fields is now built into Grafana itself. Try adding a "Organize field" transformation to your query.
Would this support your use case?
from grafana-json-datasource.
Hi there how would I use the "Organise Fields" to apply series overrides?
In the example my response will look like:
{
"data":[
{
"@timestamp":"2020-11-30T08:36:24.110Z",
"price":2575.5,
"timestamp":1606725384110,
"orderType":"1""name":"orderAdd"
},
{
"@timestamp":"2020-11-30T08:36:13.755Z",
"price":45.91,
"timestamp":1606725384110,
"orderType":"1",
"name":"orderAdd"
}, ...
]
}
In my query I isolate the following paths:
$.data[].timestamp
$.data[].prices
$.data[*].name
I want to match on the value of name attribute to apply series overrides/ Although I set the regex to /orderAdd/ I get no match.
Could you provide some guidance on what might the issue?
This works with the associated pull request as I am able to provide an alias of orderAdd which is then mapped to the name.
from grafana-json-datasource.
By default, the field name is set to the name of the property referenced by your JSON Path.
In your example, you'd end up with a query result like this:
timestamp | name | price |
---|---|---|
1606725384110 | orderAdd | 2575.5 |
1606725384110 | orderAdd | 45.91 |
With the Organize fields transform, you can for example rename the name
field to action
. Either way you can use it to specify the field to apply your override to.
The reason why you're not getting a match for /orderAdd/
is because orderAdd is a value in the name/action field rather than the name of it.
It sounds like you'd like a query response that looks something like this:
timestamp | orderAdd |
---|---|
1606725384110 | 2575.5 |
1606725384110 | 45.91 |
If this is what you're looking for, this is not supported at the moment (and wouldn't be solved with aliases). You can read more about wide and long data frames here: https://grafana.com/docs/grafana/latest/developers/plugins/data-frames/#data-frames-as-time-series.
Let me know if I've misunderstood your use case!
from grafana-json-datasource.
Thanks for the explanation. I can modify the response to look like that, but that does not feel right for an api implementation.
I was looking at the conversion to a DataFrame and in MutableDataFrame when the field is added any supplied config is added.
I think field.config.displayName is supported, could a possible solution be to give the user the ability to set an optional displayName on the query field?
from grafana-json-datasource.
Yeah, I agree it's not ideal for an API response.
Could you maybe create multiple data source queries add filter the items in the JSON Path and override the display name for each?
from grafana-json-datasource.
Yes I could create multiple data source queries in fact that is what I am doing now. How would I override the display name, as this is not currently supported?
I was thinking that as part of the query entry an optional displayName could be supplied. Is there another way?
from grafana-json-datasource.
Hi @marcusolsson,
Overriding the displayName would work. Are you happy with as a solution? It could be an optional query parameter.
The override displayName placeholder could be the current displayName.
from grafana-json-datasource.
I feel like we're discussing two different issues.
As I was trying to show with my last screenshot, Grafana already lets you override the display name of a field using field overrides. However, that will only change the name of the field. In the screenshot above, I override the price
field to orderAdd
and orderRemove
for each data source query.
The problem you seem to be having is that you'd like to turn the following response:
timestamp | name | price |
---|---|---|
1606725384110 | orderAdd | 2575.5 |
1606725384110 | orderAdd | 45.91 |
1606725384110 | orderRemove | 12.23 |
into
timestamp | orderAdd | orderRemove |
---|---|---|
1606725384110 | 2575.5 | |
1606725384110 | 45.91 | |
1606725384110 | 12.23 |
It seems to me that the root of your problem is that you want to convert between Wide and narrow data, which is a more complicated problem than simply changing the display name. Since this is a transformation that you'd want to do for a range of different panels, I'm reluctant to implementing this in this (or any) plugin.
If by "overriding display name", you mean that you want to select another field to use as the field name—essentially rotating part of the table—it's a simplification of the problem I outline above.
I want to emphasize that while I agree that this is a very useful feature, I think it's out of scope for this (any) plugin. I think it more be more suitable to implement this in Grafana itself, and offer the feature to all data sources. Please let me know if I've misunderstood your problem in any way.
from grafana-json-datasource.
Related Issues (20)
- Grafana API does not export panel annotations HOT 1
- Cannot see JSONAPI datasource in the plugin list HOT 1
- Chore: migrate to create plugin
- Suporte a paginação HOT 1
- Support multi-value variables HOT 1
- Dynamically adding fields for all JSON properties HOT 1
- Issue with multiple API calls from same chart HOT 1
- Grafana v9 - Button HOT 2
- README Shows Example that doesn't work at all [?(@.data > 'otherdata']
- Filtering in Jsonpath using Grafana multi-value variable? 'IN' operator supported? Or workarounds? HOT 1
- Audit and fix A11Y issues HOT 1
- Can't perform basic math with JSONata HOT 1
- Query error e.ArrayVector is not a constructor Getting this error after the new update. HOT 2
- Query error e.ArrayVector is not a constructor Getting this error after the new update HOT 3
- Support Sigv4 Auth
- A variable can't take another variable's value as a http request parameter if it starts with "1"
- Hope to support returning key value pairs as variables
- Show more details in console or query inspector
- TimeShift not working HOT 1
- JSON API: Bad Gateway HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grafana-json-datasource.