Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

bar chart - move the names of the columns to x-axis with vegalite and observable

I am using VegaLite and working in Observable notebook. I need to swap the labels for the column up top and x-axis, so that I have the status on top and the names on the bottom x-axis.

vegalite({
  width: 50,
  data: { values: StackVega },
  mark: 'bar',
  encoding: {
    column: {
      field: "new_name",
      type: "nominal",
      spacing: 2,
      title: "Name",
    // axis: {orient: "bottom"}
    },
    y: {
      type: "quantitative",
      aggregate: "sum",
      field: "new_rate",
      title: "Rate",
      axis: { grid: false }
    },
    x: { type: "nominal", field: "stat", axis: { title: "" } },
    color: {
      type: "nominal",
      field: "stat",
      scale: { range: ["#675193", "#ca8861"] }
    }
  },
  config: {
    view: { stroke: "transparent" },
    axis: { domainWidth: 1 }
  }
})

I have tried to add axis: {orient: "bottom"} but that didn't work and if I swap the fields with column and x it breaks the chart. enter image description here

question from:https://stackoverflow.com/questions/65600358/move-the-names-of-the-columns-to-x-axis-with-vegalite-and-observable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Column labels are not controlled by axis, they are controlled by header. Use header: {"labelOrient": "bottom"}. See Header for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...