Search code examples
vegavega-lite

Is it possible to add a background image to a plot in vega or vega-lite?


I see from https://vega.github.io/vega-lite/docs/config.html that it is possible to change the background color. But i don't see any docs for adding an underlay background image.


Solution

  • vega-lite creates a canvas element.

    So adding a background image is explained in a question about how to add a background to a canvas element.

    HTML5 Canvas background image

    But you can just do it with css:

    canvas {
      background: url("my_background.png");
    }
    

    This is just like any other background image css.

    https://developer.mozilla.org/en-US/docs/Web/CSS/background-image