[英]Brush zooming in X and Y in Vega-lite
In Vega-lite, is it possible to zoom in to a plot with a brush in the X and Y direction at the same time?在 Vega-lite 中,是否可以同时在 X 和 Y 方向使用画笔放大绘图? Using this example as a base: https://vega.github.io/vega-lite/examples/interactive_overview_detail.html使用这个例子作为基础: https : //vega.github.io/vega-lite/examples/interactive_overview_detail.html
I tried encoding the Y, but I'm not sure how to point "scale": {"domain": {"selection": "brush"}}
in the Y axis direction.我尝试对 Y 进行编码,但我不确定如何在 Y 轴方向上指向"scale": {"domain": {"selection": "brush"}}
。
If not, is it possible to achieve similar results with the "bind": "scales"
?如果没有,是否可以使用"bind": "scales"
获得类似的结果? The goal is to have a "key-map" of the chart with a zoom-in, and a small box showing where the zoom is on the broader time-series.目标是拥有一个放大的图表“关键地图”,以及一个小框,显示放大在更广泛的时间序列上的位置。
Code I've been trying with that example:我一直在尝试使用该示例的代码:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/sp500.csv"},
"vconcat": [{
"width": 480,
"mark": "area",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"scale": {"domain": {"selection": "brush"}},
"axis": {"title": ""}
},
"y": {"field": "price",
"type": "quantitative",
"scale": {"domain": {"selection": "brush"}}
}
}
}, {
"width": 480,
"height": 60,
"mark": "area",
"selection": {
"brush": {"type": "interval", "encodings": ["x","y"]}
},
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "price",
"type": "quantitative",
"axis": {"tickCount": 3, "grid": false}
}
}
}]
}`
You can do this by specifying the field
or the encoding
within the domain;您可以通过在field
指定field
或encoding
来实现此目的; for example:例如:
"domain": {"selection": "brush", "encoding": "y"}
Putting this into your example looks like this ( view live ):把它放到你的例子中看起来像这样( 查看实时):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/sp500.csv"},
"vconcat": [
{
"width": 480,
"mark": "area",
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"scale": {"domain": {"selection": "brush", "encoding": "x"}},
"axis": {"title": ""}
},
"y": {
"field": "price",
"type": "quantitative",
"scale": {"domain": {"selection": "brush", "encoding": "y"}}
}
}
},
{
"width": 480,
"height": 60,
"mark": "area",
"selection": {"brush": {"type": "interval", "encodings": ["x", "y"]}},
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {
"field": "price",
"type": "quantitative",
"axis": {"tickCount": 3, "grid": false}
}
}
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.