gpt4 book ai didi

vega-lite - 如何使刻度与条具有相同的宽度

转载 作者:行者123 更新时间:2023-12-04 10:44:44 24 4
gpt4 key购买 nike

我有这个规范:Direct-link to spec

我想以通用的方式使刻度与条一样大(如果 View 的大小发生变化,我希望刻度的宽度也发生变化)。这是一种方法吗?通过做一些转换或访问一些隐藏的变量(stepWidth ?)?我不想通过设置步长来设置我的 View 大小,因为我希望我的图表适合已定义的 DOM 元素。

enter image description here

最佳答案

我不知道以这种方式配置刻度线的任何方法。但是实现您想要的一种方法是用配置为看起来如何的笔划(即轮廓)覆盖零高度栏。例如( vega editor ):

{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"datasets": {
"$ly1": [
{
"Continent": "Asia",
"Population": 4467162
},
{
"Continent": "Europe",
"Population": 622209
},
{
"Continent": "Africa",
"Population": 1157519
},
{
"Continent": "Oceania",
"Population": 36944
},
{
"Continent": "North America",
"Population": 564626
},
{
"Continent": "Antarctica",
"Population": 6
},
{
"Continent": "South America",
"Population": 410308
}
]
},
"data": {
"name": "$ly1"
},
"autosize": {
"type": "fit",
"contains": "padding"
},
"width": {"step": 60},
"encoding": {
"x": {
"field": "Continent",
"type": "nominal"
},
"y": {
"field": "Population",
"type": "quantitative"
}
},
"layer": [
{
"mark": {
"type": "bar",
"color": "#ccc"
}
},
{
"mark": {
"type": "bar", "strokeWidth": 3
},
"encoding": {
"y2": {"field": "Continent"},
"stroke" : {
"field": "Continent",
"type": "nominal"
},
"color" : {
"field": "Continent",
"type": "nominal"
}
}
}
]
}

enter image description here

关于vega-lite - 如何使刻度与条具有相同的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59757801/

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