How can i user json-api-datasource to create pie-chart and time series chart?

my jsonapi was like this:

{
  "code": 200,
  "status": "success",
  "data": [
    {
      "metric": "ping_new_lvs_scores",
      "UpdateTime": "2024-10-10T23:18:54+08:00"
    },
    {
      "metric": "node.bw.sw.pct",
      "UpdateTime": "2024-10-10T23:12:05+08:00"
    },
    {
      "metric": "node.bw.sw.pct",
      "UpdateTime": "2024-10-10T23:12:05+08:00"
    }
  ],
  "errorType": "",
  "error": ""
}

i can use jsonata:

(
$.data{$substringBefore(metric,' '): metric[]} ~> $each(function($v, $k) {
    {
      "timestamp":"2024-01-01 00:00:00",
      "metric": $k,
      "count": $count($v.{"code": $})
    }
  })
)

to got:

[
  {
    "timestamp": "2024-01-01 00:00:00",
    "metric": "ping_new_lvs_scores",
    "count": 1
  },
  {
    "timestamp": "2024-01-01 00:00:00",
    "metric": "node.bw.sw.pct",
    "count": 2
  }
]

but in grafana,i got two [object Object], i want create a pie chart and a time series chart, how can i do that?

i have set this


but i still got two object in table view

and no date in pie chart

my grafana version is 8.4.6,is that the reason?

i used the transformations to convert the fields to time and numeric as well


i can only convert result to time
when i want to get metric, i got two objects.

where is the metric value (count) in the latest payload?


i can create pie chart using infinity datasource, so may be it is the promblem of jsonapi datasource?but in infinity i can’t count metric.

i don’t understand?

my source data is as follows:

{
  "code": 200,
  "status": "success",
  "data": [
    {
      "metric": "ping_new_lvs_scores",
      "UpdateTime": "2024-10-10T23:18:54+08:00"
    },
    {
      "metric": "node.bw.sw.pct",
      "UpdateTime": "2024-10-10T23:12:05+08:00"
    },
    {
      "metric": "node.bw.sw.pct",
      "UpdateTime": "2024-10-10T23:12:05+08:00"
    }
  ],
  "errorType": "",
  "error": ""
}

if i use this in infinity, i got one ping_new_lvs_scores one node.bw.sw.pct one node.bw.sw.pct
i want got one ping_new_lvs_scores and two node.bw.sw.pct. in json api datasource, i use jsonata to do the count job, but infinity didn’t support the count function.

Reference: Transformation functions | Grafana documentation looks like 8.4.6 didn’t support parition by values


thank you very much, it seems that i use group by in a wrong way, it is ok now.

1 Like