这是我的 vega-lite 规格
{
"data": {
"values": [
{"group": "I", "groupSort": 1, "segment": "A", "val": 1},
{"group": "II", "groupSort": 2, "segment": "B", "val": -3},
{"group": "III", "groupSort": 3, "segment": "A", "val": 2},
{"group": "IV", "groupSort": 4, "segment": "B", "val": 3},
{"group": "V", "groupSort": 5, "segment": "E", "val": -2}
]
},
"mark": {
"type": "text", "size": 20,
"text": "➟"
},
"encoding":{
"y": {
"field": "group", "type": "nominal"
},
"color": {
"condition": {"test": "datum['val'] < 0", "value": "red"},
"value": "green"},
"angle": {
"condition": {"test": "datum['val'] < 0", "value": 90},
"value": -45}
}
}
我想要的是
谢谢, 汤姆
{
"data": {
"values": [
{"group": "I", "groupSort": 1, "segment": "A", "val": 1},
{"group": "II", "groupSort": 2, "segment": "B", "val": -3},
{"group": "III", "groupSort": 3, "segment": "A", "val": 2},
{"group": "IV", "groupSort": 4, "segment": "B", "val": 3},
{"group": "V", "groupSort": 5, "segment": "E", "val": -2}
]
},
"mark": {"type": "text", "size": 20, "text": "➟"},
"encoding": {
"y": {"field": "group", "type": "nominal"},
"color": {
"condition": [
{"test": "datum['val'] < 0", "value": "red"},
{"test": "datum['val'] >= 0 && datum['val'] < 3 ", "value": "yellow"},
{"test": "datum['val'] >= 3 ", "value": "green"}
]
},
"angle": {
"condition": {"test": "datum['val'] < 0", "value": 90},
"value": -45
}
}
}