1

For some reason, my stacked bar chart doesn't display the numbers correctly on Y axis. I checked data format, tries different ones, but they are all rounded up as 0.0, 0.1 etc My min value is 500,000 and max value is 272M.

Where to look for a bug?

Here is my code:

vegalite({
  width: 600,
  height: 300,
  data: { values: TrafficAp },
  mark: {
    type: "bar",
    size: 35,
    cornerRadiusEnd: 4
  },
  encoding: {
    x: {
      timeUnit: "year_month_day",
      field: "month",
      type: "temporal",
      title: "Month",
      sort: {
        field: "month",
        order: [
          "2022-01",
          "2022-02",
          "2022-03",
          "2022-04",
          "2022-05",
          "2022-06",
          "2023-07",
          "2023-08",
          "2023-09",
          "2023-10",
          "2023-11",
          "2023-12"
        ]
      },
      scale: {
        bandPaddingInner: 0.2 // Adjust the bandPaddingInner value to change the spacing between bars
      }
    },
    y: {
      aggregate: "sum",
      type: "quantitative",
      field: "sessions",
      title: "Sessions",
      axis: {
        format: "s",
        labelExpr:
          "datum.value === 0 ? '0' : format(datum.value, '.1s').replace(/G/,'B')"
      }
    },
    color: {
      field: "traffic_type",
      type: "nominal",
      title: "Traffic Type"
    }
  },
  config: {
    stack: "normalize" // Stack bars vertically and normalize the values
  }
})```
Attached is how the bar chart looks like [![enter image description here][1]][1]
isherwood
  • 58,414
  • 16
  • 114
  • 157
Chique_Code
  • 1,422
  • 3
  • 23
  • 49
  • "Where to look for a bug?" Therein lies the power of our tags. Click on one of the tags you've added to the question (i.e. [tag:vega-lite]), then click on the Learn more... link. That has links to the library's GitHub Issues page. – Heretic Monkey Jul 13 '23 at 18:27

1 Answers1

1

Those are percentages caused by this line:

config: {
    stack: "normalize" // Stack bars vertically and normalize the values
  }

More info: https://vega.github.io/vega-lite/docs/stack.html

Davide Bacci
  • 16,647
  • 3
  • 10
  • 36