Как связать несколько графиков с помощью vega-lite только по горизонтальной оси? - PullRequest

1 Ответ

1 голос
/ 19 июня 2020

Вы можете ограничить привязку шкалы к одной оси, указав свойство "encodings" выделения. Например, это привязывает выделение только к оси x ( вид в редакторе vega ):

{
  "$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"}}
}

enter image description here

Если вам нужна независимая привязка шкалы y в каждой диаграмме с общей привязкой x, вы можете сделать это, добавив новую независимую привязку к каждой диаграмме ( редактор vega ):

{
  "$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"}}
}
...