Created
April 19, 2017 16:01
-
-
Save mattijn/a25b9ba41a775cf128d1472cd3e44253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"schema": { | |
"language": "vega", | |
"version": "3.0" | |
}, | |
"width": 500, | |
"height": 300, | |
"padding": 5, | |
"signals": [ | |
{ "name": "company", "value": "GOOG", | |
"bind": {"input": "select", "options": ["GOOG", "MSFT"]} } | |
], | |
"data": [ | |
{ | |
"name": "source", | |
"url": "data/stocks.csv", | |
"format": { | |
"type": "csv", | |
"parse": { | |
"date": "date", | |
"price": "number", | |
"company": "string" | |
} | |
}, | |
"transform": [ | |
{ | |
"type": "filter", | |
"expr": "datum[\"date\"] !== null && !isNaN(datum[\"date\"]) && datum[\"price\"] !== null && !isNaN(datum[\"price\"])" | |
}, | |
{ | |
"type": "filter", | |
"expr": "datum.symbol===company" | |
}, | |
{ | |
"type": "collect", | |
"sort": { | |
"field": "date", | |
"order": "descending" | |
} | |
} | |
] | |
} | |
], | |
"marks": [ | |
{ | |
"type": "line", | |
"from": { | |
"data": "source" | |
}, | |
"encode": { | |
"enter": { | |
"x": { | |
"scale": "xscale", | |
"field": "date" | |
}, | |
"y": { | |
"scale": "yscale", | |
"field": "price" | |
} | |
} | |
} | |
} | |
], | |
"scales": [ | |
{ | |
"name": "xscale", | |
"type": "time", | |
"domain": { | |
"data": "source", | |
"field": "date", | |
"sort": { | |
"field": "date", | |
"op": "min" | |
} | |
}, | |
"range": "width" | |
}, | |
{ | |
"name": "yscale", | |
"type": "linear", | |
"domain": { | |
"data": "source", | |
"field": "price" | |
}, | |
"range": "height", | |
"round": true, | |
"nice": true | |
} | |
], | |
"axes": [ | |
{ | |
"scale": "xscale", | |
"orient": "bottom", | |
"tickCount": 5, | |
"title": "date", | |
"offset": 10, | |
"zindex": 1, | |
"encode": { | |
"labels": { | |
"update": { | |
"text": { | |
"signal": "timeFormat(datum.value, '%b %d, %Y')" | |
}, | |
"angle": { | |
"value": 270 | |
}, | |
"align": { | |
"value": "right" | |
}, | |
"baseline": { | |
"value": "middle" | |
} | |
} | |
} | |
} | |
}, | |
{ | |
"scale": "xscale", | |
"domain": false, | |
"labels": false, | |
"offset": 10, | |
"grid": true, | |
"orient": "bottom", | |
"ticks": false, | |
"tickCount": 5, | |
"zindex": 0, | |
"gridScale": "yscale" | |
}, | |
{ | |
"scale": "yscale", | |
"format": "f", | |
"orient": "left", | |
"title": "price", | |
"grid": true, | |
"offset": 10, | |
"zindex": 0 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment