我目前正在评估我应该为开箱即用图表使用哪种类型的 js 图表引擎,而 vega-lite 同时也非常简单和灵活。但是,我想知道在一个图表中是否可以有不止一种类型的标记。例如,我可能有一个很长的月度时间序列,我可能会考虑有一个具有逐月平均值的条形层,而在一个线层中,我可能有正在进行的一年的观察的演变。
我在 vega-lite 的网页中没有看到任何带有多个标记的示例。因此,如果有人知道如何做或知道任何此类示例,我将非常感谢您的反馈。
干杯
毛里西奥
您可以使用"layers" 规范将多个点类型相互叠加。它相对较新,所以 Vega-Lite 网站上还没有很多例子,但这里有一个例子:
{
"data": {
"values": [
{"x": 1,"y": 2},
{"x": 2,"y": 4},
{"x": 3,"y": 5},
{"x": 4,"y": 3},
{"x": 5,"y": 4}
]
},
"layers": [
{
"encoding": {
"x": {"type": "quantitative","field": "x"},
"y": {"type": "quantitative","field": "y"}
},
"mark": "line",
"config": {"mark": {"color": "#1f77b4"}}
},
{
"encoding": {
"x": {"type": "quantitative","field": "x"},
"y": {"type": "quantitative","field": "y"}
},
"mark": "point",
"config": {"mark": {"color": "#ff7f0e"}}
}
]
}
Run Code Online (Sandbox Code Playgroud)
每一层都是一个编码,引用全局数据;您还可以在每个图层中指定不同的数据。
请注意,上述规范在 Vega-Lite 1.x 版中是正确的。在 Vega-Lite 2.x 版中,"layers"已更改为"layer",以及其他更改。