鼠标悬停在特定轴上时如何缩放?

时间:2020-06-19 17:04:30

标签: vega-lite

从这个concrete example开始,这里有2个图在其水平轴上链接而在其垂直轴上自由,有没有办法将鼠标悬停在特定轴上?

实际设置的缩放比例在两个轴上都是相同的。

1 个答案:

答案 0 :(得分:0)

如果要在每个面板中独立滚动,则需要做两件事:

  • resolve.scale.xresolve.scale.y设置为"independent",这样就不会链接比例尺。
  • 为每个面板中的绑定选择使用不同的名称,因此不会链接选择器。

例如(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": {"scroll_1": {"type": "interval", "bind": "scales"}}
    },
    {
      "transform": [{"filter": "datum.symbol==='GOOG'"}],
      "mark": "line",
      "encoding": {
        "x": {"field": "date", "type": "temporal"},
        "y": {"field": "price", "type": "quantitative"}
      },
      "selection": {"scroll_2": {"type": "interval", "bind": "scales"}}
    }
  ],
  "resolve": {"scale": {"x": "independent", "y": "independent"}}
}