Pie chat with json data source

Hi All,

I could able create a table view with Json data source. But I couldn’t find the json format for pie chart. Can someone help on this? Basically I want a Pie chart in the response of the Rest API.

Thanks in advance.


Hello @marcusolsson,

any suggestion from your side?

Using GitHub - marcusolsson/grafana-json-datasource: A data source plugin for loading JSON APIs into Grafana., I’m able to produce a table like this:

The first column is only dummy data. It’s added because afaik the Pie Chart panel requires a date.

When the visulation is changed to Pie Chart, nothing is displayed.

Thanks for the ping!

By default, the Pie Chart is configured for time series format. The JSON API plugin can support this format, either by creating multiple queries that all return a Time and Number field each, or by using the (currently experimental) grouping feature.

The Pie Chart also supports a row-based format, where each row in the result maps to one slice of the pie. If this is what you’re looking for, change the Show value from Calculate to All values.

1 Like

Thank you @marcusolsson for your quick reply!

After following the 2nd approach to change the Display setting of Pie Chart, it looks already much better:

However there is the next question: How to add a proper legend? Right now, it seems like the legend is taken from the “Alias” (if empty, then from the index as visible in the screenshot). Goal is to use column “b” (from my previous screenshot) as legend. I a second Field is added, its value isn’t mapped as legend to the result of the first Field.

I believe your query needs to return a String field and a Number field. The value from the string field is used as the label.

I used the Static data source to mock the response here, but you can use any data source that returns the same fields:

Using Grafana v8.1.3, it works fine whereas on v7.5 not.

Thank you!

1 Like