在单独的标记上画你的笔划。例如。
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 400,
"height": 300,
"data": {
"values": [
{"Yr": 2025, "BarName": "P101", "BarHt": 0.5, "stWidth": 5},
{"Yr": 2025, "BarName": "P102", "BarHt": 0.6, "stWidth": 1},
{"Yr": 2025, "BarName": "P103", "BarHt": 0.7, "stWidth": 5},
{"Yr": 2026, "BarName": "P104", "BarHt": 0.8, "stWidth": 1},
{"Yr": 2026, "BarName": "P105", "BarHt": 0.9, "stWidth": 5},
{"Yr": 2026, "BarName": "P106", "BarHt": 0.8, "stWidth": 1}
]
},
"transform": [
{"stack": "BarHt", "groupby": ["Yr"], "as": ["ymin", "ymax"]},
{"calculate": "(datum.ymin + datum.ymax) / 2", "as": "ymid"}
],
"encoding": {"x": {"field": "Yr"}},
"layer": [
{
"mark": {
"type": "bar"
},
"encoding": {
"y": {"field": "ymin", "type": "quantitative"},
"y2": {"field": "ymax"}
}
},
{
"mark": {
"type": "bar", "fill":"transparent",
"stroke": "black",
"strokeWidth": {"expr": "datum['stWidth']"}
},
"encoding": {
"y": {"field": "ymin", "type": "quantitative"},
"y2": {"field": "ymax"}
}
},
{
"mark": {"type": "text"},
"encoding": {
"text": {"field": "BarName"},
"y": {"field": "ymid", "type": "quantitative"}
}
}
]
}