Created
August 2, 2018 22:48
-
-
Save ericsoco/91d1833600bbec99725809a3762ffb0a to your computer and use it in GitHub Desktop.
exploring multiple y-axis series in Vega
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": "https://vega.github.io/schema/vega/v4.json", | |
"width": 500, | |
"height": 200, | |
"padding": 5, | |
"signals": [ | |
{ | |
"name": "interpolate", | |
"value": "linear", | |
"bind": { | |
"input": "select", | |
"options": [ | |
"basis", | |
"cardinal", | |
"catmull-rom", | |
"linear", | |
"monotone", | |
"natural", | |
"step", | |
"step-after", | |
"step-before" | |
] | |
} | |
} | |
], | |
"data": [ | |
{ | |
"name": "table", | |
"values": [ | |
{"x": 0, "y0": 28, "y1": 20}, | |
{"x": 1, "y0": 43, "y1": 35}, | |
{"x": 2, "y0": 81, "y1": 10}, | |
{"x": 3, "y0": 19}, | |
{"x": 4, "y0": 52}, | |
{"x": 5, "y0": 24}, | |
{"x": 6, "y0": 87, "y1": 66}, | |
{"x": 7, "y0": 17, "y1": 27}, | |
{"x": 8, "y0": 68, "y1": 16}, | |
{"x": 9, "y0": 49, "y1": 25} | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "x", | |
"type": "point", | |
"range": "width", | |
"domain": {"data": "table", "field": "x"} | |
}, | |
{ | |
"name": "y", | |
"type": "linear", | |
"range": "height", | |
"nice": true, | |
"zero": true, | |
"domain": {"data": "table", "fields": ["y0", "y1"]} | |
}, | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": ["y0", "y1"], | |
"range": ["#ff0000", "#00ff00"] | |
} | |
], | |
"axes": [ | |
{"orient": "bottom", "scale": "x"}, | |
{"orient": "left", "scale": "y"} | |
], | |
"marks": [ | |
{ | |
"type": "group", | |
"marks": [ | |
{ | |
"type": "line", | |
"from": {"data": "table"}, | |
"encode": { | |
"enter": { | |
"x": {"scale": "x", "field": "x"}, | |
"y": {"scale": "y", "field": "y0"}, | |
"stroke": {"value": "#ff0000"}, | |
"strokeWidth": {"value": 2} | |
}, | |
"update": { | |
"interpolate": {"signal": "interpolate"}, | |
"fillOpacity": {"value": 1} | |
}, | |
"hover": { | |
"fillOpacity": {"value": 0.5} | |
} | |
} | |
}, | |
{ | |
"type": "line", | |
"from": {"data": "table"}, | |
"encode": { | |
"enter": { | |
"x": {"scale": "x", "field": "x"}, | |
"y": {"scale": "y", "field": "y1"}, | |
"stroke": {"value": "#00ff00"}, | |
"strokeWidth": {"value": 2} | |
}, | |
"update": { | |
"interpolate": {"signal": "interpolate"}, | |
"fillOpacity": {"value": 1} | |
}, | |
"hover": { | |
"fillOpacity": {"value": 0.5} | |
} | |
} | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment