This website is for Vega-Lite v2. Go to the main Vega-Lite homepage for the latest release.

Format

Edit this page

In Vega-Lite specifications you can customize the format of text marks, tooltips, and axis and legend labels.

Vega-Lite uses D3’s number format pattern for quantitative fields and D3’s time format pattern for time field. You can override the default formats in the config.

Formatting text marks and tooltips

Text marks and tooltips are formatted by setting the format property of text or tooltip channel definitions.

For example, we can use Vega-Lite to show the average horsepower for cars from different origins. To format the number to have 2 digits of precisions, we can use the format .2f.

Formatting tooltips or dates is done similarly.

Formatting axis and legend labels

Quantitative fields

Below, we override the default number formatting to use exponent notation set to two significant digits.

Temporal data

In the example below we format the axis label to only show the year.

The format can also contain text.