Deneb – 无数据的切割区域(将轴的起点从0移动到特定数字)

huangapple go评论54阅读模式
英文:

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:

Deneb – 无数据的切割区域(将轴的起点从0移动到特定数字)

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.

Deneb – 无数据的切割区域(将轴的起点从0移动到特定数字)

答案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.
Deneb – 无数据的切割区域(将轴的起点从0移动到特定数字)

{
  "$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"}
      }
    }
  ]
}

huangapple
  • 本文由 发表于 2023年3月7日 14:24:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658626.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定