英文:
Deneb - Cut area with no data (move start of axe from 0 to specific number)
问题
{
"data": {"name": "dataset"},
"layer": [
{
"mark": "bar",
"encoding": {
"y": {"field": "datum_s", "type": "ordinal", "axis": {"title": "Date"}},
"yOffset": {"field": "Typ"},
"color": {"field": "Typ"},
"x": {"field": "start_n", "type": "quantitative", "axis": {"title": "Hour"}},
"x2": {"field": "end_n"}
}
},
{
"mark": "rule",
"encoding": {
"x": {"datum": 8, "type": "quantitative"},
"stroke": {"value": "darkgray"}
}
},
{
"mark": "rule",
"encoding": {
"x": {"datum": 17, "type": "quantitative"},
"stroke": {"value": "darkgray"}
}
}
],
"config": {"scale": {"x": {"zero": false}}}
}
英文:
I have this code in Deneb
{
"data": {"name": "dataset"},
"layer": [
{
"mark": "bar",
"encoding": {
"y": {
"field": "datum_s",
"type": "ordinal",
"axis": {"title": "Date"}
},
"yOffset": {"field": "Typ"},
"color": {"field": "Typ"},
"x": {
"field": "start_n",
"type": "quantitative",
"axis": {"title": "Hour"}
},
"x2": {"field": "end_n"}
}
},
{
"mark": "rule",
"encoding": {
"x": {
"datum": 8,
"type": "quantitative"
},
"stroke": {"value": "darkgray"}
}
},
{
"mark": "rule",
"encoding": {
"x": {
"datum": 17,
"type": "quantitative"
},
"stroke": {"value": "darkgray"}
}
}
]
}
sample data are:
what I want is that axe X start not from 0 but form number 7. because from hours 0 - 7 is no data and it makes huge white space in graph.
答案1
得分: 1
你可以设置一个 domainMid。我将使用之前的示例来展示,其中不再显示 0,而刻度从 1 开始。
英文:
You can set a domainMid. I'll show you using the previous example where I no longer display 0 and the scale starts at 1.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "A simple bar chart with ranged data (aka Gantt Chart).",
"width":400,
"data": {
"values": [
{"task": "A", "start": 1, "end": 3},
{"task": "B", "start": 3, "end": 8},
{"task": "C", "start": 8, "end": 10}
]
},
"layer": [
{
"mark": "bar",
"encoding": {
"y": {"field": "task", "type": "ordinal"},
"x": {"field": "start", "type": "quantitative", "scale":{"domainMin":1}},
"x2": {"field": "end"}
}
},
{
"mark": "rule",
"encoding": {
"x": {"datum": 3, "type": "quantitative"},
"stroke": {"value": "red"}
}
},
{
"mark": "rule",
"encoding": {
"x": {"datum": 7, "type": "quantitative"},
"stroke": {"value": "red"}
}
}
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论