Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rcatlord
Last active January 16, 2019 13:06
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 rcatlord/c0e8db698c061e6a0e26f924bd857d6f to your computer and use it in GitHub Desktop.
Save rcatlord/c0e8db698c061e6a0e26f924bd857d6f to your computer and use it in GitHub Desktop.
Vega-Lite example
license: cc-by-4.0
height: 300
scrolling: no
border: yes
{
"width": 300,
"title": {"text": "Top speeds of selected land animals"},
"data": {
"values": [
{"animal": "Cheetah", "kph": 120},
{"animal": "Domestic Cat", "kph": 48},
{"animal": "Elephant", "kph": 40},
{"animal": "Giraffe", "kph": 52},
{"animal": "Horse", "kph": 88},
{"animal": "Ostrich", "kph": 70},
{"animal": "Pig", "kph": 17.7},
{"animal": "Polar Bear", "kph": 30},
{"animal": "Rabbit", "kph": 48},
{"animal": "Squirrel", "kph": 20}
]
},
"transform": [{"calculate": "datum.kph*0.62137", "as": "mph"}],
"mark": "bar",
"encoding": {
"x": {
"field": "mph",
"type": "quantitative",
"axis": {"title": "Speed (mph)"}
},
"y": {
"field": "animal",
"type": "nominal",
"sort": {"field": "mph", "op": "average", "order": "descending"},
"axis": {"title": null}
},
"color": {"value": "#fc6721"},
"opacity": {"value": 0.7},
"tooltip": [
{"field": "animal", "type": "nominal", "title": "Animal"},
{
"field": "mph",
"type": "quantitative",
"title": "Speed",
"format": ".1f"
}
]
}
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vega@4.4.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2.6.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3.24.2"></script>
</head>
<body>
<div id="vis"></div>
<script type="text/javascript">
vegaEmbed('#vis', "bar_chart.vl.json", {defaultStyle: true}).catch(console.warn);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment