Deneb可视化:如何将X轴起始值从0改为7消除无数据空白
Deneb中设置X轴起始值解决空白问题
要把X轴起始值设为7,只需在条形图的X轴编码配置里添加scale属性,指定值域起始值即可。修改后的完整代码如下:
{ "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"}, "scale": {"domain": [7, null]} // 新增配置:设置X轴从7开始 }, "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"} } } ] }
关键说明
scale.domain: [7, null]强制X轴从7开始渲染,null表示自动根据数据中的最大X值(比如end_n的最大值)确定轴的结束范围,既消除0-7的空白区域,又能适配数据动态调整。- 如果需要固定X轴的结束值,可将
null替换为具体数字(比如[7, 20]),按需调整即可。
内容的提问来源于stack exchange,提问作者milenjao
相关产品推荐
相关产品推荐

