Colour Treemap Based on String Value

  • What Grafana version and what operating system are you using?
    → Browser on Mac OS

  • What are you trying to achieve?
    → I have 3 columns in my dataset. The Topic, the State and the Sum (number of website hits on that particular topic/state combination). I am trying to create a treemap where the colours of the different boxes are assigned based on the String value of that box. For example, in the first image attached, News would always be coloured red, regardless of the state it is grouped by.
    Alternatively, switching the groupings around and grouping by Topic, I would like to show the state flag image in the box that represents that state.

  • How are you trying to achieve it?
    → I am trying to configure colour changes using the Override section but it only seems to work on the underlying values (Sum column) and not the values in the State/Topic section.
    To be clear, I have managed to configure the tree itself as I want it. The problem is colouring (or inserting images) into the boxes themselves.

  • What happened?
    → The colours of the boxes only changed based on the underlying numeric values but not by the String columns

  • Can you copy/paste the configuration(s) that you are having problems with?
    → N/A

  • 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?
    → Have not found any suitable unfortunately


Using the browser version 9.3.2

Hi Pmch,

I am also using tree map. I need to colour treemap using numeric values which I am getting using query. I am trying to color treemap using override but colours are not changing.
Please reply if your map is changing using values?

Thanks,
Priyanka

One way to do it might be by assigning topic to a color value

Hello, @yosiasz @pmch Do you still use treemaps? I wanted to show the numbers (instead of labels, they can stay too). But I cannot find any settings for that. Currenlty I can see the numbers only if I click on a block.

As far as I know, there’s currently no built-in setting to always display the numeric value inside Treemap tiles. There’s an open, unimplemented feature request for this →

A practical workaround is to include the value in the label itself, since Label by simply renders whatever string field you provide.

SELECT
    topic,
    state,
    SUM(value) AS sum,
    CONCAT(topic, ' (', SUM(value), ')') AS label
FROM ...
GROUP BY topic, state;

Then set Dimensions → Label by to label. The tiles will display News (369) instead of just News.

CONCAT() works across SQL Server, PostgreSQL, and MySQL. If your database doesn’t support it, use the equivalent string concatenation operator instead.