Skip to content

Instantly share code, notes, and snippets.

@tonyxiao
Last active April 13, 2021 23:29
Show Gist options
  • Save tonyxiao/0a0d4e24d2f566295441af755da62508 to your computer and use it in GitHub Desktop.
Save tonyxiao/0a0d4e24d2f566295441af755da62508 to your computer and use it in GitHub Desktop.
stack bar with rule (Vega-Lite spec from Tue Apr 13 2021)
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 500,
"layer": [
{
"mark": {"type": "bar", "tooltip": true},
"encoding": {
"color": {"field": "supertype"},
"y": {"field": "sum", "type": "quantitative", "scale": {"padding": 1}},
"x": {
"field": "date",
"type": "temporal",
"timeUnit": "month",
"scale": {"padding": 0}
}
}
},
{
"mark": "rule",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"timeUnit": "month",
"bandPosition": 0.5
},
"y": {}
}
}
],
"data": {
"values": [
{"date": "2020-01-01", "supertype": "income", "sum": 500},
{"date": "2020-02-01", "supertype": "income", "sum": 200},
{"date": "2020-03-01", "supertype": "income", "sum": 400},
{"date": "2020-08-01", "supertype": "income", "sum": 200},
{"date": "2020-09-01", "supertype": "income", "sum": 300},
{"date": "2020-10-01", "supertype": "income", "sum": 330},
{"date": "2020-01-01", "supertype": "expense", "sum": -100},
{"date": "2020-02-01", "supertype": "expense", "sum": -250},
{"date": "2020-03-01", "supertype": "expense", "sum": -300},
{"date": "2020-08-01", "supertype": "expense", "sum": -500},
{"date": "2020-09-01", "supertype": "expense", "sum": -800},
{"date": "2020-10-01", "supertype": "expense", "sum": -900}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment