Overrides for Bar charts

Hi!

I am seeing odd behavior when modifying the panel’s JSON to update overrides directly.

For the sake of this post I’ll simplify things:

  1. I have a field (Field_1)
  2. There are two distinct values (“yes” and “no”)
  3. I want to create a bar chart where the “yes” bar is green, and the “no” bar is red.

Here’s what’s odd - when I apply my override to a pie chart (again, updating the JSON directly) it works, but if I duplicate and switch the chart type to bars, it does not. Has anyone experienced this? If so, how do we work around this?

do you have a numeric value to go along with the yes and no fields?

The SQL I wrote is as follows:

SELECT 
  Field_1,
  COUNT(*)

FROM TABLE
GROUP BY 1

The COUNT(*) should work as my numeric field, right?

I think @sowdenraymond meant: do you know which numerical value you want to be yes or no?
such as a 1 is a yes and a 0 a no for example.
By the way, even if it’s not what he meant, this info might still be useful.

what version of grafana are you working with?

Cloud, so should be the latest.

1 Like

I don’t have a numeric field as I am counting rows and grouping by Field_1. Should I assign a numerical value to “yes” and “no”?

counting is usually a numeric field :laughing:

created by mocking your data

with src
as
(

  select top 10 left(name,4) as Field_1 from sys.columns
)
SELECT 
  Field_1,
  COUNT(1)

FROM src
GROUP BY Field_1

then bar chart using overrides value mapping

2 Likes

Hi there - just tried your solution, but didn’t work for me. Not sure why. Out of curiosity, did you do any transformations to achieve the mappings in the bar chart, or are you using manual overrides alone?

using mock data

with src
as
(

  select top 10 left(name,4) as Field_1 from sys.columns
)
SELECT 
  Field_1,
  COUNT(*)

FROM src
GROUP BY Field_1

I see - what I need is to color my bars based on dimension value, not metric value. Not sure if that changes anything. So, for example, I would want (in your example) the “bina” bar to be blue, regardless of value.

please identify what you consider dimension vs metric

A dimension, in my case, would be the unique values in field_1 (in my example, these would be ‘yes’ and ‘no’). The metric associated is the COUNT(*) that is calculated after the GROUP BY statement (also above).

So, in a bar graph, I want the “yes” bar to be green, and the “no” bar to be red. I am able to achieve this in both pie charts and time series (each section or breakdown line is the correct color), but the same overwrite method does not work for a bar graph.

In fact, I just changed the bar chart to a pie chart, and my overrides were picked up immediately. Not sure why a bar chart wouldn’t be able to understand an override that a donut chart can.