我正在制作一个包含 4 年数据的图表,但我省略了 2021 年。它位于我的域的中间,所以我不知道如何将其从图表中取出。今年的数据没有任何值。
另外,如果可能的话,让 2019 年和 2023 年不要超出图表线的边缘也是很好的。
代码如下:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "https://raw.githubusercontent.com/sebastipasti/seba27.github.io/refs/heads/main/VA%20tinker.csv"},
"mark": {"type": "bar", "width": {"band": 1},
"cornerRadiusEnd": 2},
"encoding": {
"x": {
"field": "Year",
"type": "temporal",
"axis": {"domain": false, "grid": false},
"scale": {"nice": false, "zero": false},
"title": "Year"
},
"y": {
"field": "Value",
"type": "quantitative",
"axis": {"domain": false, "grid": false, "offset": 20},
"title": null,
},
"xOffset": {"field": "Group"},
"color": {
"field": "Group",
"type": "nominal",
"scale": {
"domain": ["Violence against the person", "Rape", "Sexual offences", "Robbery", "Theft offences", "Criminal damage and arson", "Drug offences", "Possession of weapons", "Public order offences", "Miscellaneous crimes against society", "Fraud offences"],
"range": ["#9e0142", "#d53e4f", "#f46d43", "#fdae61", "#fee08b", "#ffffbf", "#e6f598", "#abdda4", "#66c2a5", "#3288bd", "#5e4fa2"]
},
"title": "Offence Group"
},
"order": {"field": "order", "type": "ordinal"}
},
"resolve": {"scale": {"x": "independent"}}
}
谢谢
像这样吗?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"url": "https://raw.githubusercontent.com/sebastipasti/seba27.github.io/refs/heads/main/VA%20tinker.csv"
},
"mark": {"type": "bar", "width": {"band": 1}, "cornerRadiusEnd": 2},
"encoding": {
"x": {
"field": "Year",
"type": "ordinal",
"axis": {"domain": false, "grid": false},
"title": "Year"
},
"y": {
"field": "Value",
"type": "quantitative",
"axis": {"domain": false, "grid": false, "offset": 20},
"title": null
},
"color": {
"field": "Group",
"type": "nominal",
"scale": {
"domain": [
"Violence against the person",
"Rape",
"Sexual offences",
"Robbery",
"Theft offences",
"Criminal damage and arson",
"Drug offences",
"Possession of weapons",
"Public order offences",
"Miscellaneous crimes against society",
"Fraud offences"
],
"range": [
"#9e0142",
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#ffffbf",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd",
"#5e4fa2"
]
},
"title": "Offence Group"
},
"order": {"field": "order", "type": "ordinal"}
},
"resolve": {"scale": {"x": "independent"}}
}