悬停的着色线对仅在VEGA-LITE中的线与线与线相同



我正在测试与vega-lite中的线图相互作用,在那里我希望在悬停在悬停的情况下进行彩色,其余的线为灰色。一个简单的版本正常工作。但是,如果我将规格更改为将点添加到线上,则悬停行为似乎并不像线相同。这是我测试的具体示例。这是此示例的规范:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "description": "Stock prices of 5 Tech Companies over Time.",
  "data": {"url": "data/stocks.csv"},
  "selection": {"pts": {"type": "single", "on": "mouseover"}},
  "mark": {
    "type": "line",
    "point": {
      "filled": true
    }
  },
  "encoding": {
    "x": {"timeUnit": "year", "field": "date", "type": "temporal"},
    "y": {"aggregate":"mean", "field": "price", "type": "quantitative"},
    "color": {
      "condition": {
        "selection": "pts",
        "field":"symbol",
        "type": "nominal"
      },
      "value": "grey"
    }
  }
}

我期望在悬停在点或线段段上时,所选线的所有段和点都应颜色,所有其他线及其点应为灰色。我看到的是,悬停在点上只显示工具提示,实际上并没有改变颜色。悬停在线上为线上颜色,但其点仍然变为灰色。另外,在悬停在某个点之后,如果我试图悬停在相应行的一段,什么也不会发生。

如果将 "encodings": ["color"]添加到选择定义中,则将应用于所有颜色编码。在这里尝试:( Vega编辑器(

{
  "$schema": "https://vega.github.io/schema/vega-lite/v3.json",
  "description": "Stock prices of 5 Tech Companies over Time.",
  "data": {
    "url": "data/stocks.csv"
  },
  "selection": {
    "pts": {
      "type": "single",
      "on": "mouseover",
      "encodings": ["color"]
    }
  },
  "mark": {
    "type": "line",
    "point": {
      "filled": true
    }
  },
  "encoding": {
    "x": {
      "timeUnit": "year",
      "field": "date",
      "type": "temporal"
    },
    "y": {
      "aggregate": "mean",
      "field": "price",
      "type": "quantitative"
    },
    "color": {
      "condition": {
        "selection": "pts",
        "field": "symbol",
        "type": "nominal"
      },
      "value": "grey"
    }
  }
}

相关内容

  • 没有找到相关文章

最新更新