Минимальное значение для оси Y в Vega Lite - PullRequest
1 голос
/ 07 апреля 2020

У меня есть линейный график с биржевыми тиками, основанный на следующих примерах: https://vega.github.io/vega-lite/examples/interactive_multi_line_pivot_tooltip.html

Я пытаюсь установить мин. вал. для оси у и попробовал следующее:

    "encoding": {
        "x": {
            "field": "date",
            "type": "temporal"
        },
        "y": {
            "field": "price",
            "type": "quantitative",
            "scale": {"domain": [150,350]},
        },
    },

Это работает с отрицательными значениями, такими как -150, но не положительными. Также моя подсказка исчезает при установке переменных y ..

1 Ответ

0 голосов
/ 07 апреля 2020

Настройка домена масштаба, похоже, работает с примером, с которым вы связаны ( редактор ):

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"url": "data/stocks.csv"},
  "width": 400,
  "height": 300,
  "encoding": {"x": {"field": "date", "type": "temporal"}},
  "layer": [
    {
      "encoding": {
        "color": {"field": "symbol", "type": "nominal"},
        "y": {
          "field": "price",
          "type": "quantitative",
          "scale": {"domain": [100, 500]}
        }
      },
      "layer": [
        {"mark": {"type": "line", "clip": true}},
        {
          "transform": [{"filter": {"selection": "hover"}}],
          "mark": {"type": "point", "clip": true}
        }
      ]
    },
    {
      "transform": [{"pivot": "symbol", "value": "price", "groupby": ["date"]}],
      "mark": "rule",
      "encoding": {
        "opacity": {
          "condition": {"value": 0.3, "selection": "hover"},
          "value": 0
        },
        "tooltip": [
          {"field": "AAPL", "type": "quantitative"},
          {"field": "AMZN", "type": "quantitative"},
          {"field": "GOOG", "type": "quantitative"},
          {"field": "IBM", "type": "quantitative"},
          {"field": "MSFT", "type": "quantitative"}
        ]
      },
      "selection": {
        "hover": {
          "type": "single",
          "fields": ["date"],
          "nearest": true,
          "on": "mouseover",
          "empty": "none",
          "clear": "mouseout"
        }
      }
    }
  ]
}

enter image description here

Обратите внимание, что я также установил свойство метки clip, чтобы скрыть метки за пределами границ оси.

...