gpt4 book ai didi

vega - 重命名 Vega 图中的图例值并保持颜色一致

转载 作者:行者123 更新时间:2023-12-02 04:22:23 26 4
gpt4 key购买 nike

我的数据包含 3 列 - 日期、类别和值。该类别是我想扩展的一个短字符串代码,例如“r”=>“常规”,“n”=>“禁止”等,并显示正确的图例字符串。有没有办法让映射 {"r":"regular", "n": "prohibited"}- 未列出的内容按原样显示?

另外,由于我有很多相似的图表,我希望颜色保持一致。对类别进行排序没有帮助,因为并非所有图表都包含所有类别。如何设置映射 {"r":"blue", "n": "#332211"} 我可以使用映射的类别名称,例如“regular”。所有非映射值应来自其他来源,例如 Category20 等。

最佳答案

您可以在内置“scatter ”示例中使用此变体来为各个标签设置自定义标题。查看“legend_labels”比例。

{
"width": 200,
"height": 200,
"data": [
{
"name": "iris",
"url": "data/iris.json"
}
],
"scales": [
{
"name": "legend_labels",
"type": "ordinal",
"domain": ["setosa", "versicolor", "virginica"],
"range": ["SET", "VER", "VIR"]
},
{
"name": "x",
"nice": true,
"range": "width",
"domain": {"data": "iris", "field": "data.sepalWidth"}
},
{
"name": "y",
"nice": true,
"range": "height",
"domain": {"data": "iris", "field": "data.petalLength"}
},
{
"name": "c",
"type": "ordinal",
"domain": {"data": "iris", "field": "data.species"},
"range": ["#800", "#080", "#008"]
}
],
"axes": [
{"type": "x", "scale": "x", "offset": 5, "ticks": 5, "title": "Sepal Width"},
{"type": "y", "scale": "y", "offset": 5, "ticks": 5, "title": "Petal Length"}
],
"legends": [
{
"fill": "c",
"title": "Species",
"offset": 0,
"properties": {
"symbols": {
"fillOpacity": {"value": 0.5},
"stroke": {"value": "transparent"}
},
"labels": {
"text": {"scale": "legend_labels", "field": "data"}
}
}
}
],
"marks": [
{
"type": "symbol",
"from": {"data": "iris"},
"properties": {
"enter": {
"x": {"scale": "x", "field": "data.sepalWidth"},
"y": {"scale": "y", "field": "data.petalLength"},
"fill": {"scale": "c", "field": "data.species"},
"fillOpacity": {"value": 0.5}
},
"update": {
"size": {"value": 100},
"stroke": {"value": "transparent"}
},
"hover": {
"size": {"value": 300},
"stroke": {"value": "white"}
}
}
}
]
}

同样,您可以自定义单独的颜色,如上面的“c”比例。

不幸的是,目前没有任何方法可以为未映射的值自定义任何后备行为,因此您需要确保您的比例包含域中的所有值。最好针对该功能提出增强请求。

关于vega - 重命名 Vega 图中的图例值并保持颜色一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29419432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com