如何避免带图层的折线图中的缩放冲突?
How to avoid zoom conflict in a line chart with layer?
VEGA-lite 并不完美,但非常好,通常对于看起来像错误的东西,有一个解决方法...所以我假设在这个 "bug" 中我们有一个解决方法.
((回答后编辑:这不是真正的错误,是规范语言上的 "semantic bug"))
奇怪的行为,一个"semantic bug":我在一个琐碎的上下文中使用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'"}] }
]
}
解决方法:如,
"the interval selection must be added to one of the layers"。但是
怎么做 "interval selection"?
我图表上的数据不是静态的,我需要一个随它变化的区间,所以,设置区间没有意义。
我提到的 "interval selection" 是您图表中的区间选择定义:
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 模式指定必须在单元规范(即单个层)内声明选择。
VEGA-lite 并不完美,但非常好,通常对于看起来像错误的东西,有一个解决方法...所以我假设在这个 "bug" 中我们有一个解决方法.
((回答后编辑:这不是真正的错误,是规范语言上的 "semantic bug"))
奇怪的行为,一个"semantic bug":我在一个琐碎的上下文中使用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'"}] }
]
}
解决方法:如
怎么做 "interval selection"?
我图表上的数据不是静态的,我需要一个随它变化的区间,所以,设置区间没有意义。
我提到的 "interval selection" 是您图表中的区间选择定义:
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 模式指定必须在单元规范(即单个层)内声明选择。