vega-lite - 如何避免带图层的折线图中的缩放冲突?
问题描述
VEGA-lite 并不完美,但非常好,而且通常对于看起来像错误的东西,有一个解决方法......所以我假设在这个“错误”中我们有一个解决方法。
((回答后编辑:它不是真正的错误,是规范语言上的“语义错误”))
奇怪的行为,一个“语义错误”:我selection: { "grid": {"type":"interval", "bind":"scales"} }
用简单的mark: 'line'
. 当我添加layer
时,它停止工作。
{
title: "Número de registros por minuto (n_count normalizado)",
$schema: vglVers,
data: { "url":"mySQLtable" },
selection: { "grid": {"type":"interval", "bind":"scales"} }, // was working with simple mark
//mark: 'line',
width:340,
encoding: {
x: {"field": "instant", "type": "temporal"},
y: {"field": "n_pmin", "type": "quantitative"},
color: {"field": "symbol", "type": "nominal"}
},
layer: [
{
"mark": {"type": "line", "point": true},
"transform": [{"filter": "datum.symbol == 'n_pmin'"}]
},
{ "mark": {"type": "line"}, "transform": [{"filter": "datum.symbol != 'n_pmin'"}] }
]
}
解决方法:正如@jakevdp 在这里评论的那样, “必须将间隔选择添加到其中一个层”。但
这个“区间选择”怎么做?
我图表上的数据不是静态的,我需要一个随它变化的间隔,所以设置间隔没有意义。
解决方案
我提到的“区间选择”是图表中的区间选择定义:
selection: { "grid": {"type":"interval", "bind":"scales"} }
不能在顶层图表中声明;您必须在其中一层声明它:
{
title: "Número de registros por minuto (n_count normalizado)",
$schema: vglVers,
data: { "url":"mySQLtable" },
width:340,
encoding: {
x: {"field": "instant", "type": "temporal"},
y: {"field": "n_pmin", "type": "quantitative"},
color: {"field": "symbol", "type": "nominal"}
},
layer: [
{
"mark": {"type": "line", "point": true},
"transform": [{"filter": "datum.symbol == 'n_pmin'"}],
"selection": {"grid": {"type":"interval", "bind":"scales"}},
},
{
"mark": {"type": "line"},
"transform": [{"filter": "datum.symbol != 'n_pmin'"}]
}
]
}
您的问题不是错误,我的解决方案也不是解决方法:vega-lite 模式指定必须在单元规范(即单个层)中声明选择。
推荐阅读
- nginx - SSL_do_handshake() 在 cloudflare 后面使用 nginx-proxy 失败
- fpga - HLS:如何分离 AXI4 信号
- javascript - 如何使用自定义错误消息捕获“TypeError:无法读取未定义的属性(读取'0')”?
- spring - Kotlin Spring:未解决的参考方法
- python - 获取重复行和文件的其余部分[大文件50G]
- javascript - 如何动态导入 NextJs 页面数据(数组)而不是整个组件
- html - 如何垂直居中搜索栏?
- javascript - 如何摆脱“错误:Windows 上的 SPAWN ls ENONET”?
- symfony - Symfony 5.3 Mailer 设置环境变量无法正确读取
- java - 当我的 Spring Batch Job 完成时,如何调用 writer 类的方法?