Skip to content

Instantly share code, notes, and snippets.

@JamesWilmot
Created March 29, 2022 10:43
Show Gist options
  • Select an option

  • Save JamesWilmot/645aae208d52206dbd44b4ffa7cc4e00 to your computer and use it in GitHub Desktop.

Select an option

Save JamesWilmot/645aae208d52206dbd44b4ffa7cc4e00 to your computer and use it in GitHub Desktop.
Solar demo vega spec
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A basic area chart example.",
"width": 1000,
"height": 400,
"padding": 5,
"data": [
{
"name": "table",
//"values": data,
"url": "https://gist.githubusercontent.com/JamesWilmot/39117ed0b6296646a67da46076edc598/raw/5b301a874ff15736b106cb88db1b463c1226769b/solar_data.json",
"transform": [
{
"type": "formula",
"expr": "toDate(datum[\"DateTime\"])",
"as": "DateTime"
},
]
},
/*
{
"name": "selected",
"on": [
{"trigger": "clear", "remove": true},
{"trigger": "!shift", "remove": true},
{"trigger": "!shift && clicked", "insert": "clicked"},
{"trigger": "shift && clicked", "toggle": "clicked"}
]
}
*/
],
/*
"legends": [
{
"stroke": "cscale",
"title": "Year",
"padding": 4,
"encode": {
"symbols": {
"enter": {
"strokeWidth": {"value": 2},
"size": {"value": 50}
}
}
}
}
],
*/
"scales": [
{
"name": "xscale",
"type": "time",
"range": "width",
"zero": false,
"domain": {"data": "table", "field": "DateTime"}
},
{
"name": "yscale",
"type": "linear",
"range": "height",
"nice": true,
"zero": true,
"domain": {"data": "table", "field": "Energy"}
},
{
"name": "yscale2",
"type": "linear",
"range": "height",
//"domainMax": 5000,
//"nice": true,
"zero": true,
"domain": {"data": "table", "field": "Power"}
//"domain": {"data": "table", "field": "v"}
}
],
"axes": [
{"orient": "bottom", "scale": "xscale", "tickCount": 20, "title": "Time"},
{"orient": "left", "scale": "yscale", "title": "Energy (kw/h)"},
{"orient": "right", "scale": "yscale2", "title": "Power (watt)"}
],
"marks": [
{
"type": "area",
"from": {"data": "table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "DateTime"},
"y": {"scale": "yscale", "field": "Energy"},
"y2": {"scale": "yscale", "value": 0},
"fill": {"value": "steelblue"},
"interpolate": {"value": "natural"}
},
"hover": {
//"fillOpacity": {"value": 0.5}
}
}
},
{
"type": "line",
"from": {"data": "table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "DateTime"},
"y": {"scale": "yscale2", "field": "Power"},
"interpolate": {"value": "natural"}
},
"hover": {
//"fillOpacity": {"value": 0.5}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment