Is it possible to add a vertical bar denoting a time span to my vega-lite visualization?

29 Views Asked by At

I have a scatter plot graph with a regression line. I'd like to add a vertical line showing which dates are used to make a calculation on my dashboard. The calculation involves using data from the most recent three weeks. I'd like to visualize that by adding a vertical line on each side maybe in bracket form. enter image description here How could I add these brackets to my vega lite visualization?

1

There are 1 best solutions below

0
Greg Philps On

I'm not aware of anything you could use as curly brackets, but another option might be to layer your plot with a "rect" mark behind (a background rectangle; see simple example below) and a "point" mark in front (the scatter plot).

{
  "name": "BACKGROUND_RECTANGLE",
  "data": {
    "values": [
      {
        "Start": "09-Nov-2023",
        "End": "28-Nov-2023"
      }
    ],
    "format": {
      "parse": {
        "Start": "date:'%d-%b-%Y'",
        "End": "date:'%d-%b-%Y'"
      }
    }
  },
  "mark": {
    "type": "rect",
    "opacity": 0.4
  },
  "encoding": {
    "x": {
      "field": "Start",
      "type": "temporal"
    },
    "x2": {"field": "End"},
    "color": {
      "value": "lightgrey"
    }
  }
}