Search code examples
vega-lite

How can I change opacity of area mark or specifically, how do I define opacity of gradient stops?


In this example, how can I change the opacity of the area mark? I am trying to change the opacity of the area to 1 (fully opaque).

Adding "opacity": 1 or "fillOpacity": 1 to mark does not seem to work. On the other hand, while defining Gradient, one can only define a color for a stop but not the opacity.

Edit: dominic's answer below can be used to define opacity of gradient stops. However, there seems to be a bug for defining opacity of Area marks: https://github.com/vega/vega-lite/issues/5807


Solution

  • You can use this format for colors rgba(R, G, B, A) where A is the alpha.

    "color": {
      "x1": 1,
      "y1": 1,
      "x2": 1,
      "y2": 0,
      "gradient": "linear",
      "stops": [
        {
          "offset": 0,
          "color": "rgba(0, 255, 0, 0)"
        },
        {
          "offset": 1,
          "color": "rgba(0, 255, 0, 1)"
        }
      ]
    }
    

    enter image description here

    To set the opacity to 1, you can use an encoding

    "opacity": {
      "value": 1
    }