How to give color to each sub category bar in Bar Chart?

  • What Grafana version and what operating system are you using?
    9.5.1

  • What are you trying to achieve?
    I want to give color to each my education_category bar that grouped in salary_category x-axis

  • How are you trying to achieve it?
    I am using bar chart, and confused how to change the color for each sub category bar. I tried using override, but the result is different.

  • What happened?
    The desired result do not produced

  • What did you expect to happen?
    I want Senior High School, College, Master and Doctorate have different color of bar chart in $40K-$60K up until > $120K category

  • Can you copy/paste the configuration(s) that you are having problems with?
    this is my query and my data

SELECT
cdh.income_category,
edb.education_level,
COUNT(*) AS count
FROM customer_data_history cdh
JOIN education_db edb
ON cdh.educationid = edb.id
WHERE cdh.income_category IN (β€˜Less than $40K’, β€˜$40K - $60K’, β€˜$60K - $80K’, β€˜$80K - $120K’, β€˜$120K +’)
AND cdh.idstatus = 2 AND cdh.gender = β€˜M’
GROUP BY cdh.income_category, edb.education_level
ORDER BY cdh.income_category, edb.education_level;

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    no

  • Did you follow any online instructions? If so, what is the URL?
    Yes, i read override, treshold, mapping but still confused
    Configure thresholds | Grafana documentation

2 Likes

Welcome

Your database design approach is a bit worrisome especially

Less than $40K’, β€˜$40K - $60K’, β€˜$60K - $80K’, β€˜$80K - $120K’, β€˜$120K +
. But that is your choice.

Here is what you can try.
image

image

Thanks for the reply @yosiasz , I will try your suggestion right now.

For the salary data, you are absolutely correct. That data is a test for me as I am now currently pursuing certification for data engineering. And the designated Instructor challenge me to learn grafana for the chance working on his company.

1 Like

It looks like you’re trying to customize the colors of your bar chart in Grafana based on different education categories within salary categories. Here are some suggestions to help you achieve your goal:

  1. Ensure Correct Data Grouping: Your query looks correct for grouping the data by income and education levels. Ensure that the data is being returned as expected.
  2. Using Overrides in Grafana:
  • Go to the Panel settings of your bar chart.
  • Navigate to the Overrides tab.
  • Add an override and select the field (series) you want to change.
  • In the override options, set the color for each series.
  1. Color Scheme Configuration:
  • In the Display options of your bar chart, you can set the color scheme to β€˜By Series’.
  • This will allow Grafana to automatically assign different colors to each series (education level in your case).
  1. Thresholds for Custom Colors:
  • If you want specific colors for each education level, you might need to use the Thresholds option.
  • Define thresholds for each education category and assign the desired color.
  1. Example Configuration:
  • For each education level, add an override and assign a unique color:
    • Senior High School: Color #1
    • College: Color #2
    • Master: Color #3
    • Doctorate: Color #4
  1. Documentation and Tutorials:
  • You mentioned you followed the Grafana documentation. Double-check the Grafana Bar Chart Documentation for additional details on configuring colors and overrides.
  1. Visual Examples:
  • It might help to look at examples or screenshots of similar configurations. If available, share or look for community posts or tutorials that illustrate how to set up colored bar charts with multiple categories.

By following these steps, you should be able to configure your Grafana bar chart to display different colors for each education category within the salary categories.

1 Like