我使用 vegalite 创建一个图表并在条形颜色中应用渐变,但我想为渐变中定义的颜色创建参数,基本上想在渐变上绑定一个参数 我只是尝试不通过设置参数 barcolor 来工作 --
我如何将其与颜色 vai 参数绑定
梯度不支持信号,但您可以在信号中定义梯度。
例如
Here you could switch between two different gradients - test1 and test2.
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 200,
"height": 200,
"padding": 5,
"signals": [
{
"name": "test1",
"update": "{gradient: 'linear', stops: [{offset: 0, color: 'green'}, {offset: 1, color: 'red'}]}"
},
{
"name": "test2",
"update": "{gradient: 'linear', stops: [{offset: 0, color: 'red'}, {offset: 1, color: 'green'}]}"
}
],
"marks": [
{
"type": "rect",
"encode": {
"enter": {
"x": {"value": 0},
"x2": {"value": 100},
"y": {"value": 0},
"y2": {"value": 400},
"fill": {"signal": "test1"}
}
}
}
]
}