我正在尝试创建共享相同轴的条形图和符号图。我遇到的问题是符号与栏的顶部而不是中心对齐。通过 vega 提供的配置选项是否可以实现这一点?我查看了 vega 文档 here ,但找不到这样的解释或适用的例子。
{
"data": [{"name": "dataset"}],
"scales": [
{
"name": "yscale",
"type": "band",
"domain": {
"data": "dataset",
"field": "Sector"
},
"range": "height",
"padding": 0.1,
"round": true
},
{
"name": "xscale",
"domain": {
"data": "dataset",
"field": "Position Weight"
},
"nice": true,
"range": "width"
}
],
"axes": [
{
"scale": "xscale",
"orient": "bottom",
"title": "Position Weight"
},
{
"orient": "left",
"scale": "yscale",
"title": "Sector"
}
],
"marks": [
{
"type": "rect",
"from": {"data": "dataset"},
"encode": {
"enter": {
"tooltip": {
"signal": "datum"
},
"x": {
"scale": "xscale",
"field": "Position Weight"
},
"x2": {
"scale": "xscale",
"value": 0
},
"y": {
"scale": "yscale",
"field": "Sector"
},
"height": {
"scale": "yscale",
"band": 1
},
"opacity": {"value": 1}
}
}
},
{
"type": "symbol",
"from": {"data": "dataset"},
"encode": {
"enter": {
"tooltip": {
"signal": "datum"
},
"x": {
"scale": "xscale",
"field": "Record Count"
},
"x2": {
"scale": "xscale",
"value": 0
},
"y": {
"scale": "yscale",
"field": "Sector"
},
"height": {
"scale": "yscale",
"band": 1
},
"opacity": {"value": 1}
},
"update" :{"fill": {"value": "red"}},
"baseline": {"value": "bottom"}
}
}
]
}
最佳答案
你的意思是这样吗?
如果是这样,请在符号上设置带。
{
"data": [{"name": "dataset"}],
"scales": [
{
"name": "yscale",
"type": "band",
"domain": {
"data": "dataset",
"field": "Sector"
},
"range": "height",
"padding": 0.1,
"round": true
},
{
"name": "xscale",
"domain": {
"data": "dataset",
"field": "Position Weight"
},
"nice": true,
"range": "width"
}
],
"axes": [
{
"scale": "xscale",
"orient": "bottom",
"title": "Position Weight"
},
{
"orient": "left",
"scale": "yscale",
"title": "Sector"
}
],
"marks": [
{
"type": "rect",
"from": {"data": "dataset"},
"encode": {
"enter": {
"tooltip": {
"signal": "datum"
},
"x": {
"scale": "xscale",
"field": "Position Weight"
},
"x2": {
"scale": "xscale",
"value": 0
},
"y": {
"scale": "yscale",
"field": "Sector"
},
"height": {
"scale": "yscale",
"band": 1
},
"opacity": {"value": 1}
}
}
},
{
"type": "symbol",
"from": {"data": "dataset"},
"encode": {
"enter": {
"tooltip": {
"signal": "datum"
},
"x": {
"scale": "xscale",
"field": "Record Count"
},
"x2": {
"scale": "xscale",
"value": 0
},
"y": {
"scale": "yscale", "band":0.5,
"field": "Sector"
},
"opacity": {"value": 1}
},
"update" :{"fill": {"value": "red"}},
"baseline": {"value": "bottom"}
}
}
]
}
关于powerbi - 如何垂直对齐符号,以便它们与 y 轴标签对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75524757/