The config object is a JSON object that is different from the specification that describes the visualisation. It is used to apply default styles to the visualisation, and can be completely overridden by the content of the specification.
It aims to provide a consistent look and identity to the charts. All without preventing any tweaks or further customisations for specific pieces of work.
How to use it?
If you use Vega’s online editor to build your charts, just copy the config below and paste it in the config editor. It is located on the left-hand side of the interface and can be accessed by clicking the tab called “Config”.
Before going forward with building your own charts, please have a read at the rest of the page as it contains important information on the color ranges, the legend and extra care to take when using Vega examples.
General config
Note: to quickly copy the code, click the content_copy icon.
Color ranges
The config contains all the color schemes and ramps defined in the colors section of the style guide.
Below, you’ll find how to choose which scheme or ramp to use and how to apply it to your chart.
Categorical data
If your data is categorical, or will be displayed on a bar or pie chart, you will most likely use the qualitative scheme.
When defining the scale that will determine the color of the marks, make sure its range
is set to category
. For example, this is a scale using the qualitative scheme:
Continuous (numerical) data
If your data is composed of numerical values, the config lets you choose between a large choice of sequential or divergent ramps.
Below are the names of the ramps:
diverging
(divergent ramp)reds
purples
blues
greens
oranges
To use any of them, this is how you would like to define the scale (here we use purples
):
Tweaks for the legend
The legend of your chart will be heavily dependent on your data. That’s why we’re proposing two layouts:
- One layout where it is at the bottom of the chart
- One where it is on the right side
We’d recommend to use the first layout (at the bottom) when the legend contains very few items, and the other, when it contains more.
In both cases, we would recommend not to add a title to the legend to avoid cluttering the visualisation.
The custom config positions the legend at the bottom of the chart. To place the legend at the side of the visualization, you need to slightly alter the code by replacing the legend
object by this one:
Note on using Vega examples
While useful to start with, most of Vega’s examples override some of the defaults set in the config. This include paddings, colors and opacities. When using one of the them, please consider removing all the styling properties that you don’t actually need.