Skip to content

Instantly share code, notes, and snippets.

@domoritz
Last active April 12, 2020 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domoritz/29eab69c5d0cf9e8a4abce4fa54dcc94 to your computer and use it in GitHub Desktop.
Save domoritz/29eab69c5d0cf9e8a4abce4fa54dcc94 to your computer and use it in GitHub Desktop.
Vega-Lite Locale Example
license: bsd-3-clause
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@4"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
</head>
<body>
<div id="vis"></div>
<script>
const spec = "line.vl.json";
vegaEmbed("#vis", spec, {
timeFormatLocale: {
// copied from https://github.com/d3/d3-time-format/blob/master/locale/it-IT.json
"dateTime": "%A %e %B %Y, %X",
"date": "%d/%m/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
"shortDays": ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"],
"months": ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
"shortMonths": ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"]
}
})
// result.view provides access to the Vega View API
.then(result => console.log(result))
.catch(console.warn);
</script>
</body>
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width": 600,
"data": {"url": "https://vega.github.io/vega-datasets/data/stocks.csv"},
"transform": [{"filter": "datum.symbol==='GOOG'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment