Skip to content

Instantly share code, notes, and snippets.

@kanitw
Forked from domoritz/.block
Last active February 23, 2018 05:22
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 kanitw/a5d94c58af359c73068aa94f9220b668 to your computer and use it in GitHub Desktop.
Save kanitw/a5d94c58af359c73068aa94f9220b668 to your computer and use it in GitHub Desktop.
Vega-Lite Bl.ocks example
license: bsd-3-clause
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
<style>
body {
font-family: sans-serif;
}
.vega-actions a {
padding: 0.2em;
}
</style>
</head>
<body>
<div id="vis"></div>
<script>
const spec = "vl.vl.json";
vegaEmbed('#vis', spec).catch(console.warn);
</script>
</body>
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {
"url": "https://npm-stat.com/downloads/range/2016-01-01:9999-01-01/vega-lite",
"format": {
"property": "downloads"
}
},
"title": "Vega-Lite's NPM Downloads per Month",
"width": 280,
"height": 200,
"layer": [{
"mark": {
"type": "line",
"interpolate": "monotone"
},
"encoding": {
"x": {
"timeUnit": "utcyearmonth",
"field": "day",
"type": "temporal",
"axis": {
"title": null,
"labelFlush": false
}
},
"y": {
"field": "downloads",
"type": "quantitative",
"axis": {
"title": null
},
"aggregate": "sum"
}
}
}, {
"mark": "circle",
"encoding": {
"x": {
"timeUnit": "utcyearmonth",
"field": "day",
"type": "temporal"
},
"y": {
"field": "downloads",
"type": "quantitative",
"aggregate": "sum"
}
}
}, {
"transform": [
{
"timeUnit": "utcyearmonth",
"field": "day",
"as": "yearmonth"
},{
"aggregate": [{
"op": "sum",
"field": "downloads",
"as": "downloads"
}],
"groupby": ["yearmonth"]
},{
"aggregate": [{
"op": "max",
"field": "yearmonth",
"as": "last_day"
}, {
"op": "max",
"field": "downloads",
"as": "downloads"
}],
"groupby": []
}
],
"mark": {
"type":"text",
"dx": 10,
"align": "left",
"baseline": "left"
},
"encoding": {
"x": {"field": "last_day", "type": "temporal"},
"y": {"field": "downloads", "type": "quantitative"},
"text": {"field": "downloads", "type": "quantitative"}
}
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment