Search code examples
vega-lite

Set default font in vega lite


Can I set a font, e.g. in vega-lite's config object, that is used for all the labels and titles?

I currently set labelFont and titleFont for the x&y axis and the color legend, but it is the same font everywhere so it would be nice to set it just once.


Solution

  • Unfortunately no, there does not appear to be a global font setting in Vega-Lite. But you can set all fonts in the figure (for example to "monospace") with the following config:

    "config": {
      "axis": {"labelFont": "monospace", "titleFont": "monospace"},
      "legend": {"labelFont": "monospace", "titleFont": "monospace"},
      "header": {"labelFont": "monospace", "titleFont": "monospace"},
      "mark": {"font": "monospace"},
      "title": {"font": "monospace", "subtitleFont": "monospace"}
    }
    

    Alternatively, if you have control of the browser page where the chart is being rendered, you can set the default font for the div that the chart appears in using standard CSS.