如何在使用重复配置时启用对图例的鼠标点击事件。

huangapple go评论56阅读模式
英文:

How to enable mouse click even on legend with repeat configuration

问题

我正在使用重复配置,并且可以使用此配置绘制多个系列。但是,当我尝试设置参数并尝试与图例绑定时,它会报“重复信号”的错误。我还在使用 Spec 配置。感谢您提前的帮助。

英文:

i am using repeat configuration and i could able to draw multiple series using this configuration. However when i try to set the params and try to bind with legend, it gives error duplicate signal. I am also using Spec configuration.

Appreciate your help in advance

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "data/movies.json"},
  "repeat": {"layer": ["US Gross", "Worldwide Gross"]},
  "spec": {
    "mark": "line",
    "encoding": {
      "x": {"bin": true, "field": "IMDB Rating", "type": "quantitative"},
      "y": {
        "aggregate": "mean",
        "field": {"repeat": "layer"},
        "type": "quantitative",
        "title": "Mean of US and Worldwide Gross"
      },
      "color": {"datum": {"repeat": "layer"}, "type": "nominal"}
    }
  }
}

答案1

得分: 1

以下是您要的翻译内容:

正如我在上面的评论中指出的,当结合"params"与使用"layer""repeat"视图组合时,似乎存在已知的 bug(GitHub 链接)。

考虑到这一点,您需要重新设计您的规范以实现所需的结果。以下是一个基于您提供的示例的样本(示例链接)。关键的方法是使用"fold"转换,从"US Gross""Worldwide Gross"创建新的"key""value"字段。通过这个变化,这两行现在可以在单个图层中显示,并且交互式图例现在可以正常工作。

英文:

As noted in my comment above, there appears to be a known bug when combining "params" with a "repeat" view composition that uses "layer" in particular (GitHub link).

With this in mind, you'll need to refactor your specification to achieve the desired result. Here is a sample based on your provided example (example link). The key approach here is to use a "fold" transform to create new "key" and "value" fields from "US Gross" and "Worldwide Gross". With this change, the two lines can now be displayed within a single layer, and the interactive legend will now work.

huangapple
  • 本文由 发表于 2023年6月8日 13:55:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428959.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定