【问题标题】:set maximum value for x-axis in vegalite doesn't work properly在 vegalite 中为 x 轴设置最大值无法正常工作
【发布时间】:2020-11-12 01:44:03
【问题描述】:

我想在 vegalite 水平条形图中将我的 x 轴值设置为 0 到 360。这是我的代码:

vegalite({
  width: 600,
  height: 300,
  data: { values: AdPitchedInd },
  mark: 'bar',
  encoding: {
    x: {
      aggregate: "sum",
      field: "occurence",
      type: "quantitative",
      scale: { domain: [0, 360] }
    },
    y: { field: "industry", type: "nominal" },
    color: { field: "ad_pitched", type: "nominal" }
  }
})

我已经为 x 轴设置了比例和域,但它不起作用。我仍然有从 0 到 400 的轴。当我将其更改为 340 时,它可以工作但似乎卡在 360...

【问题讨论】:

    标签: svg scale vega-lite


    【解决方案1】:

    默认情况下,vega-lite 为指定域选择“漂亮”的视觉边界,这有时甚至可以覆盖明确请求的域。您可以通过在轴刻度内设置nice=false 来关闭此行为:

    vegalite({
      width: 600,
      height: 300,
      data: { values: AdPitchedInd },
      mark: 'bar',
      encoding: {
        x: {
          aggregate: "sum",
          field: "occurence",
          type: "quantitative",
          scale: { domain: [0, 360], nice: false }
        },
        y: { field: "industry", type: "nominal" },
        color: { field: "ad_pitched", type: "nominal" }
      }
    })
    

    【讨论】:

    • 有趣!非常感谢,效果很好!
    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多