如何 link 仅在水平轴上使用 vega-lite 绘制多个图?
How to link multiple plots with vega-lite only on horizontal axis?
但没有成功,因为垂直轴也已链接。
还有一种方法可以将滚轮缩放限制在一个轴上吗?
您可以通过指定选择的 "encodings"
属性 将比例绑定限制到单个轴。例如,这会将选择仅绑定到 x 轴 (view in vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/stocks.csv"},
"vconcat": [
{
"transform": [{"filter": "datum.symbol==='IBM'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"region": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
},
{
"transform": [{"filter": "datum.symbol==='GOOG'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"region": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
}
],
"resolve": {"scale": {"x": "shared", "y": "independent"}}
}
如果您想在每个图表中使用独立的 y 刻度绑定,共享 x 绑定,您可以通过在每个图表中添加一个新的独立绑定选择来实现(vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/stocks.csv"},
"vconcat": [
{
"transform": [{"filter": "datum.symbol==='IBM'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"y_scroll_1": {"type": "interval", "bind": "scales", "encodings": ["y"]},
"x_scroll": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
},
{
"transform": [{"filter": "datum.symbol==='GOOG'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"y_scroll_2": {"type": "interval", "bind": "scales", "encodings": ["y"]},
"x_scroll": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
}
],
"resolve": {"scale": {"x": "shared", "y": "independent"}}
}
但没有成功,因为垂直轴也已链接。 还有一种方法可以将滚轮缩放限制在一个轴上吗?
您可以通过指定选择的 "encodings"
属性 将比例绑定限制到单个轴。例如,这会将选择仅绑定到 x 轴 (view in vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/stocks.csv"},
"vconcat": [
{
"transform": [{"filter": "datum.symbol==='IBM'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"region": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
},
{
"transform": [{"filter": "datum.symbol==='GOOG'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"region": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
}
],
"resolve": {"scale": {"x": "shared", "y": "independent"}}
}
如果您想在每个图表中使用独立的 y 刻度绑定,共享 x 绑定,您可以通过在每个图表中添加一个新的独立绑定选择来实现(vega editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"data": {"url": "data/stocks.csv"},
"vconcat": [
{
"transform": [{"filter": "datum.symbol==='IBM'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"y_scroll_1": {"type": "interval", "bind": "scales", "encodings": ["y"]},
"x_scroll": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
},
{
"transform": [{"filter": "datum.symbol==='GOOG'"}],
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"}
},
"selection": {
"y_scroll_2": {"type": "interval", "bind": "scales", "encodings": ["y"]},
"x_scroll": {"type": "interval", "bind": "scales", "encodings": ["x"]}
}
}
],
"resolve": {"scale": {"x": "shared", "y": "independent"}}
}