Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bruno_hcr
New Member

Deneb Vega - Gradient based on values of a specific column instead of fixed offsets

Hi everyone!

 

I'm trying to create an area chart with gradient on Deneb with Vega. The idea is to set the colors of the gradient based on the values of my column called "percentage_score". This particular column have values varying from 0.0 to 100.0. If the value of the "percentage_score" in a particular month is bettween 0.0 and 50.0 i want the area to be red, from 50 it should start to become yellow and only become green if gets to 100.0.

 

Here is what I got so far:

bruno_hcr_0-1709325391823.png

 

 

As you can see its not correct because it should be green only if the value is 100.0. I'm not being able to find a way

to make the gradient colors behave based on my "percentage_score" column. Here is a piece of my dataset:

 

bruno_hcr_1-1709325392026.png

 

 

There is a way to bring the "percentage_score" to the offset values? For now the colors offset are behaving based on the area chart instead of the scores:

 

"marks": [
    {
      "name": "layer_0_layer_0_marks",
      "type": "area",
      "style": ["area"],
      "sort": {"field": "month_order_fy", "order": "ascending"},
      "from": {"data": "data_1"},
      "encode": {
        "update": {
          "opacity": {"value": 1},
          "orient": {"value": "vertical"},
          "fill": {
            "value": {
              "x1": 1,
              "y1": 1,
              "gradient": "linear",
              "stops": [
                {"offset": 0, "color": "#ff1414"},
                {"offset": 0.5, "color": "#ffdf48"},
                {"offset": 1, "color": "#00FFCD"}
              ]
            }
          },
          "description": {
            "signal": "\"Month-Year: \" + (isValid(datum[\"Month-Year\"]) ? datum[\"Month-Year\"] : \"\"+datum[\"Month-Year\"]) + \"; percentage_score: \" + (format(datum[\"percentage_score\"], \"\"))"
          },
          "x": {"scale": "x", "field": "Month-Year", "band": 0.5},
          "y": {"scale": "y", "field": "percentage_score_end"},
          "y2": {"scale": "y", "field": "percentage_score_start"},
          "defined": {
            "signal": "isValid(datum[\"percentage_score\"]) && isFinite(+datum[\"percentage_score\"])"
          }
        }
      }
    }
2 REPLIES 2
giammariam
Super User
Super User

@bruno_hcr for your gradient stops, see if something like the following is closer to what you're after:

      "stops": [
        {"offset": 0, "color": "red"},
        {"offset": 0.25, "color": "red"},
        {"offset": 0.99, "color": "yellow"},
        {"offset": 1, "color": "green"}
      ]


Madison Giammaria
Proud to be a Super User 😄
LinkedIn

Do you frequently use Deneb to provide insights to your stakeholders? Have you considered sponsoring this free and open source custom visual? More info here!
dm-p
Super User
Super User

Hi @bruno_hcr,

 

You can define a gradient object as a signal and refer to this in the fill encoding. Please refer to this StackOverflow answer for an example.

 

Regards,


Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors