![](/img/trans.png)
[英]Vega-lite: Change order of stacks in a stacked bar chart and ignore negative value
[英]Remove empty values from grouped bar chart in Vega-lite
使用 Vega-lite 我正在创建一个分组条形图,其中学校按 x 轴上的Size
字符串变量分组。 Y 轴是定量的。 我几乎可以使用它,但目前每个组都在每个学校的 x 轴上包括一个点,包括不在该组中的那些,因此不显示任何数据。 例如:
我如何确保学校只出现在它们所属的类别中? 除了我在网上发现的一个例子外,使用旧版本的 Vega-lite 做这类事情并试图对它们进行逆向工程是徒劳的。
var barGroupCreate = {
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
data: { values: toolData },
config: { view: { stroke: "transparent" }, axis: { domainWidth: 1 } },
spacing: { column: 10 },
facet: {
column: {
field: "Size",
type: "nominal",
header: { orient: "bottom" },
},
},
spec: {
width: { step: 12 },
mark: "bar",
encoding: {
y: {
aggregate: "sum",
field: "Contact Hours (Total)",
title: "Contact Hours",
axis: { grid: false },
},
x: { field: "Name", axis: null },
color: {
field: "Size",
scale: {
range: [
"#002D74",
"#F26852",
"#2A7DE1",
"#FFD100",
"#00A9C5",
"#3A4A9F",
],
},
},
},
},
};
我的数据示例( toolData
):
"values": [
{
"Name": "Alamo",
"Contact Hours (Total)": 19930352,
"Size": "Very large",
},
{
"Name": "Alvin",
"Contact Hours (Total)": 2211352,
"Size": "Medium",
},
{
"Name": "Amarillo",
"Contact Hours (Total)": 4363650,
"Success Points (Total)": 16945,
"Size": "Large",
},
{
"Name": "Angelina",
"Contact Hours (Total)": 1983398,
"Size": "Medium",
},
{
"Name": "Austin",
"Contact Hours (Total)": 14027493,
"Size": "Very large",
},
{
"Name": "Blinn",
"Contact Hours (Total)": 7594730,
"Size": "Large",
},
您可以通过添加来做到这一点
resolve: {scale: {x: "independent"}}
在barGroupCreate
内。
更多信息请访问https://vega.github.io/vega-lite/docs/facet.html#resolve
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.