Stacked Bar Chart (Vega)

Stacked bar chart
{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "A stacked bar chart example.",
  "width": 400,
  "height": 200,
  "padding": 5,

  "data": [
    {
      "name": "table",
      "values": [
        {"category": "A", "type": "X", "amount": 28},
        {"category": "A", "type": "Y", "amount": 55},
        {"category": "B", "type": "X", "amount": 43},
        {"category": "B", "type": "Y", "amount": 91},
        {"category": "C", "type": "X", "amount": 81},
        {"category": "C", "type": "Y", "amount": 53}
      ]
    }
  ],

  "scales": [
    {
      "name": "xscale",
      "type": "band",
      "domain": {"data": "table", "field": "category"},
      "range": "width",
      "padding": 0.05
    },
    {
      "name": "yscale",
      "type": "linear",
      "domain": {"data": "table", "field": "amount"},
      "nice": true,
      "range": "height"
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "table", "field": "type"},
      "range": {"scheme": "category10"}
    }
  ],

  "axes": [
    {"orient": "bottom", "scale": "xscale"},
    {"orient": "left", "scale": "yscale"}
  ],

  "marks": [
    {
      "type": "rect",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"scale": "xscale", "field": "category"},
          "width": {"scale": "xscale", "band": 1},
          "y": {"scale": "yscale", "field": "amount"},
          "y2": {"scale": "yscale", "value": 0},
          "fill": {"scale": "color", "field": "type"}
        },
        "update": {
          "fillOpacity": {"value": 1}
        },
        "hover": {
          "fillOpacity": {"value": 0.5}
        }
      }
    }
  ]
}