# Can I define color range in Object

**URL:** https://discuss.elastic.co/t/can-i-define-color-range-in-object/266095
**Category:** Kibana
**Created:** [March 3, 2021, 11:35am UTC](https://discuss.elastic.co/t/can-i-define-color-range-in-object/266095 "2021-03-03T11:35:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ChrisaT](https://avatars.discourse-cdn.com/v4/letter/c/47e85d/32.png) [@ChrisaT](https://discuss.elastic.co/u/ChrisaT)
#### Post date: [March 3, 2021, 11:35am UTC](https://discuss.elastic.co/t/can-i-define-color-range-in-object/266095/1 "2021-03-03T11:35:56Z")

</div>

Hi, im having issues with visualisations and defining colour ranges. Although I can override the colour via the legend in the visualisation adding this into a Canvas ignores the colours I set. It reverts to the default green to red.

Can I define the colours within the object? E.g. add a colour value to each range defined and remove the colorSchema.

```
"metric": {
  "percentageMode": false,
  "useRanges": false,
  "colorSchema": "Green to Red",
  "metricColorMode": "Labels",
  "colorsRange": [
    {
      "from": 0,
      "to": 9
    },
    {
      "from": 9,
      "to": 16
    },
    {
      "from": 16,
      "to": 18
    },
    {
      "from": 18,
      "to": 21
    },
    {
      "from": 21,
      "to": 24
```

---

<div class="post-metadata">

### Author: ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)
#### Post date: [March 5, 2021, 4:17am UTC](https://discuss.elastic.co/t/can-i-define-color-range-in-object/266095/2 "2021-03-05T04:17:06Z")

</div>

I see that you are looking for conditional coloring in Canvas. There are few threads which discuss this in detail.See if it helps:

> [@Conditional colouring using kibana canvas expression editor](https://discuss.elastic.co/t/conditional-colouring-using-kibana-canvas-expression-editor/177929/7):
>
> @Catherine_Liu I have basically the same problem not with the font color but with the background color I have just one condition instead of two my approach is quite like the fist you gave to ksunil. I do a select count(\*) and if it is greater than 0 the backround should be green otherwise it should be red. The expression editor looks like below filters | essql query="SELECT \* FROM uacuser WHERE logintime \> NOW() - INTERVAL 1 MONTH AND disabled = 0" | math "size(userid)" | metric "Users logge…

and there is a GH issue as well

> <https://github.com/elastic/kibana/issues/35496>
>
> \*\*Describe the feature:\*\*
> As a Canvas users, I want to change the appearance of… an element based upon an underlying value. For example, set the metric font to red if a value under a specified threshold. 
> 
> \*\*Describe a specific use case for the feature:\*\*
> Whether I'm building a report or dashboard in Canvas, I may way want to emphasize a negative state by putting more visual emphasis on an element. This could be useful when there are a high level of negative occurrences (errors, security findings, etc.); likewise for positive occurrences. This could also be used for positioning, size, etc.
> 
> You can currently do this through the expression editor like so:
> \`\`\`
> demodata
> | math "unique(country)"
> | metric "Countries" 
> metricFont={font size=48 family="'Open Sans', Helvetica, Arial, sans-serif" color={if {gt 10} then=red else=black} align="center" lHeight=48}
> \`\`\`
> 
> It is a question that comes up regularly which is why adding it to the UI (side panel settings) would be a nice way make this feature more discoverable. At first, it may simply be enough UI to handle two states that equate to an \`if then else\` statement. In the initial version, this could be visually assembled with some simple text inputs.
> 
> I can provide mockups, if necessary, when this is ready to be worked on.

Hope it helps  
Thanks  
Rashmi

cc @Catherine_Liu

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 2, 2021, 4:17am UTC](https://discuss.elastic.co/t/can-i-define-color-range-in-object/266095/3 "2021-04-02T04:17:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
