У меня есть график в vega-lite и я пытаюсь изменить цвет точек и линий в зависимости от верхнего предела (obeGrenze) зеленой заштрихованной области, например, установить цвет на красный, если точка выше этого верхнего предела. Код:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "A dual axis chart, created by setting y's scale resolution to `\"independent\"`",
"width": 300, "height": 300,
"data": {
"url": "https://pnwscm60.github.io/data/chdeath.csv"
},
"axis": {
"font": "Open Sans Condensed"
},
"encoding": {
"x": {
"field": "date",
"axis": {"format": "%d.%m", "title": null},
"type": "temporal",
"timeUnit": "daymonth"
}
},
"layer": [
{
"mark": {"opacity": 0.3, "type": "area", "color": "#85C5A6"},
"transform": [{"filter": "datum.Alter == \"65\""}],
"encoding": {
"y": {
"aggregate": "average",
"field": "obeGrenze",
"scale": {"domain": [0, 1800]},
"type": "quantitative",
"axis": {"title": "Anzahl wöchentliche Todesfälle", "titleColor": "#111","format": ".2r"}
},
"y2": {
"aggregate": "average",
"field": "untGrenze"
}
}
},
{
"mark": {"opacity": 0.3, "type": "area", "color": "#85C5A6"},
"transform": [{"filter": "datum.Alter == \"0-64\""}],
"encoding": {
"y": {
"aggregate": "average",
"field": "obeGrenze",
"scale": {"domain": [0, 1800]},
"type": "quantitative"
},
"y2": {
"aggregate": "average",
"field": "untGrenze"
}
}
},
{
"mark": {
"stroke":"#85A9C5", "type": "line", "interpolate": "monotone","point": true},
"transform": [{"filter": "datum.Alter == \"0-64\""}],
"encoding": {
"y": {
"aggregate": "mean",
"field": "hochrechnung",
"type": "quantitative",
"axis": {}
}
}
},
{
"mark": {
"stroke": "#85A9C5", "type": "line", "interpolate": "monotone","point": ""},
"transform": [{"filter": "datum.Alter == \"65\""}],
"encoding": {
"y": {
"aggregate": "mean",
"field": "hochrechnung",
"type": "quantitative"
}
}
},
{
"mark": "point",
"transform": [{"filter": "datum.Alter == \"65\""}],
"encoding": {
"y": {
"aggregate": "mean",
"field": "hochrechnung",
"type": "quantitative"
},
"tooltip": [{"field": "Woche", "type":"quantitative"},{"field": "hochrechnung", "type":"quantitative"}],
"fill": { "value": "#fff" }
}
},
{
"mark": "point",
"transform": [{"filter": "datum.Alter == \"0-64\""}],
"encoding": {
"y": {
"aggregate": "mean",
"field": "hochrechnung",
"type": "quantitative"
},
"tooltip": [{"field": "Woche", "type":"quantitative"},{"field": "hochrechnung", "type":"quantitative"}],
"fill": { "value": "#fff" }
}
}
]
}
Я могу изменить цвет с помощью условия, например "test": "datum ['hochrechnung']> 100", но когда я пытаюсь использовать переменную вместо числа (например, "datum" ['obeGrenze'] ", у меня нет никакого эффекта.
Как мне этого добиться?