由于某种原因,我的堆积条形图无法在 Y 轴上正确显示数字。我检查了数据格式,尝试了不同的格式,但它们都四舍五入为 0.0、0.1 等我的最小值是 500,000,最大值是 272M。
在哪里寻找错误?
这是我的代码:
vegalite({
width: 600,
height: 300,
data: { values: TrafficAp },
mark: {
type: "bar",
size: 35,
cornerRadiusEnd: 4
},
encoding: {
x: {
timeUnit: "year_month_day",
field: "month",
type: "temporal",
title: "Month",
sort: {
field: "month",
order: [
"2022-01",
"2022-02",
"2022-03",
"2022-04",
"2022-05",
"2022-06",
"2023-07",
"2023-08",
"2023-09",
"2023-10",
"2023-11",
"2023-12"
]
},
scale: {
bandPaddingInner: 0.2 // Adjust the bandPaddingInner value to change the spacing between bars
}
},
y: {
aggregate: "sum",
type: "quantitative",
field: "sessions",
title: "Sessions",
axis: {
format: "s",
labelExpr:
"datum.value === 0 ? '0' : format(datum.value, '.1s').replace(/G/,'B')"
}
},
color: {
field: "traffic_type",
type: "nominal",
title: "Traffic Type"
}
},
config: {
stack: "normalize" // Stack bars vertically and normalize the values
}
})
这些是由这条线引起的百分比:
config: {
stack: "normalize" // Stack bars vertically and normalize the values
}