Hi Question on colour in visuals. I am creating vi...
# gooddata-cloud
c
Hi Question on colour in visuals. I am creating visuals where the customer wants them to highlight red/amber/green but each visual needs a custom rule for this. is there anyway to do this in gooddata
k
Great question! GoodData offers a couple of approaches for red/amber/green (RAG) color highlighting in visuals, but the availability depends on the visualization type. 1. Conditional Number Formatting (Tables & Headlines) For table and headline reports, you can apply conditional color formatting directly in the metric format string. This is the most flexible option for RAG rules per metric. [conditional formatting] Example — color values based on thresholds:
Copy code
[<600000][red]$#,#.##;[=600000][yellow]$#,#.##;[>600000][green]$#,#.##
You can also set background colors:
Copy code
[>=.9][backgroundcolor=990000][white]#,##0%;
[>=.7][backgroundcolor=AD3333][white]#,##0%;
[>=.5][backgroundcolor=C26666]#,##0%;
[backgroundcolor=F5E6E6]#,##0%
Each metric can have its own custom rule, so different visuals can have different thresholds. However, this only works for tables and headline (KPI) reports — it does not apply to bar charts or other chart types. [color formatting limit] 2. Color Mapping via GoodData.UI SDK (Charts) For embedded chart visualizations (using the GoodData.UI SDK), you can use
colorMapping
to assign specific colors to individual measures or attribute elements programmatically. This allows per-visualization custom rules in code: [color mapping]
Copy code
<InsightView
    insight="<InsightView-id>"
    config={{
        colorMapping: [{
            predicate: (headerItem) =>
                headerItem.measureHeaderItem?.localIdentifier === "m1_localIdentifier",
            color: {
                type: "rgb",
                value: { r: 255, g: 0, b: 0 } // Red
            }
        }, {
            predicate: (headerItem) =>
                headerItem.measureHeaderItem?.localIdentifier === "m2_localIdentifier",
            color: {
                type: "rgb",
                value: { r: 0, g: 128, b: 0 } // Green
            }
        }]
    }}
/>
colorMapping
overrides all other color settings and can be defined differently per visualization component. Summary > âš ī¸ Note: Conditional color formatting (red/green based on value thresholds) is not supported for bar charts or other non-table/headline visualizations in the standard UI. 👍 0 button 👎 0 button â„šī¸ Tip: Mention @kapa.ai in the thread for follow-ups. 👀 Our Support team monitors all messages and will jump in if needed., with interactive elements
s
Hi Chris. We can confirm our AI's answer. Please follow it and let us know if you need any further help.
✅ 1
c
Thank I will try the conditional formatting option
👍 1
Is there anyway to do the conditional formatting based on a metric?
s
Hi Chris, Yes, conditional formatting based on a metric's value is supported. You can define color and format rules in the metric's format string using conditions like
[<600000][red]$#,#.##;[>600000][green]$#,#.##
. Here are the details: conditional formatting.
c
sorry i mean based on a different metric than the one that i am formatting
s
Thank you for the clarification, Chris. Conditional formatting applies only to a metric's own values. It means you cannot format one metric based on another metric's value.
c
Thank you
👍 1