Customizing pie chart colors: cannot replicate the play.grafana example

  • Grafana 8.4.4 Mac - localhost - Docker

I’m trying to customize a piechart colors based on a field value. This was done on the browser market share piechart given as an examle:
https://play.grafana.org/d/ktMs4D6Mk/5-bar-charts-and-pie-charts?orgId=1&editPanel=2

I see that they built an override with a “Fields with Name” displaying the value “Chrome (not found)” so it can be assigned a single color. They picked purple, and if you go to the sidebar and change the single color to a different one, you see the Chrome browser sector color changing.

I am unable to replicate this on my end for my piechart (that displays fine but with the classic palette color): I cannot enter a value in my override “Fields with name”. I have two columns in my query: status (string) and count (numeric) and these are the only accepted values I can select from the menu

I would like to save the value “On hold” , which exists in my column status, but the Fields with name value changes back to status

Thank you for your input!

can you please follow these steps to share your raw unformatted data? That way, the community can try and mock up your problem :+1:

I actually found the nasty trick used to achieve this: It is not about the data, it’s about temporarily tweaking the query by creating column names after the values of my ‘status’ column, to lure Grafana and make it believe there are fields with these names

Here is my initial query

SELECT 
(CASE 
WHEN orderstatus = 0 THEN 'Received'
WHEN orderstatus = 1 THEN 'Completed'
WHEN orderstatus = 2 THEN 'On hold'
WHEN orderstatus = 3 THEN 'Priority'
ELSE 'Printed'
END
) AS status,
COUNT(orderstatus) AS nborders
FROM salesorders
GROUP BY orderstatus

I temporarily changed it to:

SELECT 
(CASE 
WHEN orderstatus = 0 THEN 'Received'
WHEN orderstatus = 1 THEN 'Completed'
WHEN orderstatus = 2 THEN 'On hold'
WHEN orderstatus = 3 THEN 'Priority'
ELSE 'Printed'
END
) AS status,
'Received',
'Completed',
'On Hold',
'Priority',
'Printed',
COUNT(orderstatus) AS nborders
FROM salesorders
GROUP BY orderstatus

Once I have this, I can create four overrides and select for each of them the values “Printed”, etc… and pick my single color.

Once done, I delete the columns I added to my query, triggering the (not found) in my overrides Fields with name, like in the example.

As for my data inspection, here it is:


Screen Shot 2022-04-29 at 9.59.02 PM

I found an easier way thanks to this post.

Simply click on one of the legend color options and choose a different color. This will then automatically create a field override for that specific value (visible in the “Overrides” right panel)

1 Like