From c5b262e46b7f19d78dd17a986992bcb414d34d95 Mon Sep 17 00:00:00 2001 From: FAQ Bot Date: Sun, 6 Sep 2026 15:04:00 +0000 Subject: [PATCH 1/2] NEW: Why do Grafana pie charts show `n` or only one feedback slice even when --- ...-charts-rows-to-fields-relevance-feedba.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 _questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md diff --git a/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md b/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md new file mode 100644 index 00000000..a7194563 --- /dev/null +++ b/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md @@ -0,0 +1,35 @@ +--- +id: 0cf2421dca +question: Why do Grafana pie charts show `n` or only one feedback slice even when + the PostgreSQL query returns separate relevance/feedback categories? +sort_order: 8 +--- + +If your PostgreSQL query returns multiple categories as multiple rows (e.g., `feedback`, `n`), but your pie chart is configured/reducing to a single numeric field (often `n`), Grafana may collapse the rows and end up with only one slice. + +Fix: use the `Rows to fields` transformation so each category becomes its own numeric field. + +In the panel editor: +1) Set the PostgreSQL query `Format` to `Table` and ensure it returns one row per category, with: + - a text category column (e.g., `feedback`) + - a numeric count column (e.g., `n`) +2) Open `Transformations` → `Add transformation` → `Rows to fields`. +3) In the field mapping table: + - set the category column (e.g., `feedback`) to `Use as` → `Field name` + - set the count column (e.g., `n`) to `Use as` → `Field value` +4) Use the resulting fields in the pie chart. + - With one count per field, use `Calculate` → `Last (not null)` to keep each category as its own slice. + - Enable legend names/values to verify you get e.g. `thumbs up: 3` and `thumbs down: 2`. + +Example read-only query (two feedback categories): +```SQL +WITH feedback_counts(feedback, n) AS ( +VALUES ('thumbs up', 3), ('thumbs down', 2) +) +SELECT feedback, n +FROM feedback_counts; +``` + +Why this happens: Grafana can reduce a numeric column named `n` to a single value (often the last one), which produces one slice. Renaming labels alone doesn’t split the data into separate numeric fields per category—`Rows to fields` does. + +Note: this kind of transform doesn’t populate an empty result; validate using real aggregates from the same DB and time range you’re charting. \ No newline at end of file From e52443c4d3139711ccfcec06cf6db646aaf5ed64 Mon Sep 17 00:00:00 2001 From: Alexey Grigorev Date: Wed, 9 Sep 2026 15:45:43 +0200 Subject: [PATCH 2/2] Fix Grafana pie FAQ: restore references and validation (#377) --- ...a_grafana-pie-charts-rows-to-fields-relevance-feedba.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md b/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md index a7194563..b43632eb 100644 --- a/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md +++ b/_questions/llm-zoomcamp/module-5/008_0cf2421dca_grafana-pie-charts-rows-to-fields-relevance-feedba.md @@ -32,4 +32,9 @@ FROM feedback_counts; Why this happens: Grafana can reduce a numeric column named `n` to a single value (often the last one), which produces one slice. Renaming labels alone doesn’t split the data into separate numeric fields per category—`Rows to fields` does. -Note: this kind of transform doesn’t populate an empty result; validate using real aggregates from the same DB and time range you’re charting. \ No newline at end of file +Note: this kind of transform doesn't populate an empty result; validate using real aggregates from the same DB and time range you're charting. The example above should display `thumbs up: 3` and `thumbs down: 2` (5 votes total), not one slice labelled `n`. This was verified with Grafana 10.2.3 and a PostgreSQL datasource. + +References: + +- [Grafana: Rows to fields transformation](https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/#rows-to-fields) +- [Grafana 10.2.3 rowsToFields implementation](https://github.com/grafana/grafana/blob/v10.2.3/public/app/features/transformers/rowsToFields/rowsToFields.ts)