参考这篇文章
我想理解下面代码行中的表达式
"params":
[
{"name": "max", "expr": "data('data_0')[0]['max']"},
{"name": "min", "expr": "data('data_0)[0]['min']"}
]
我尝试实现相同的代码并尝试进行更改,但它不起作用。 y 轴未绘制。
{
"data": {"name": "dataset"},
"title": "All Points",
"transform": [
{
"joinaggregate": [
{
"op": "max",
"field": "dollar_price",
"as": "_max"
},
{
"op": "min",
"field": "dollar_price",
"as": "_min"
}
]
}
],
"params": [
{
"name": "Max_Range",
"expr": "data('dataset')[0]['_max']"
},
{
"name": "Min_Range",
"expr": "data('dataset')[0]['_min']"
}
],
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "dollar_price",
"type": "quantitative",
"scale": {
"domain": {
"expr": "[Min_Range,Max_Range]"
}
}
},
"color": {
"field": "country_name",
"type": "nominal"
}
},
"layer": [
{"mark": "line"},
{
"mark": {
"type": "point",
"size": 20
}
},
{
"mark": {
"type": "text",
"align": "left",
"baseline": "middle",
"dy": -10
},
"transform": [
{
"calculate": "format(datum.dollar_price,'.1f')",
"as": "New_Text"
}
],
"encoding": {
"text": {
"field": "New_Text",
"type": "quantitative"
}
}
}
]
}
VL 对原始数据集执行各种操作。试试这个:
{
"data": {"name": "dataset"},
"title": "All Points",
"transform": [
{
"joinaggregate": [
{
"op": "max",
"field": "dollar_price",
"as": "_max"
},
{
"op": "min",
"field": "dollar_price",
"as": "_min"
}
]
}
],
"params": [
{
"name": "Max_Range",
"expr": "data('data_0')[0]['_max']"
},
{
"name": "Min_Range",
"expr": "data('data_0')[0]['_min']"
}
],
"encoding": {
"x": {
"field": "date",
"type": "temporal"
},
"y": {
"field": "dollar_price",
"type": "quantitative",
"scale": {
"domain": {
"expr": "[Min_Range,Max_Range]"
}
}
},
"color": {
"field": "country_name",
"type": "nominal"
}
},
"layer": [
{"mark": "line"},
{
"mark": {
"type": "point",
"size": 20
}
},
{
"mark": {
"type": "text",
"align": "left",
"baseline": "middle",
"dy": -10
},
"transform": [
{
"calculate": "format(datum.dollar_price,'.1f')",
"as": "New_Text"
}
],
"encoding": {
"text": {
"field": "New_Text",
"type": "quantitative"
}
}
}
]
}