Stacked Bar Chart order of Groups

Hi! I'm drawing a stacked bar chart using some sample data:

return [
  { location: "East",
    amplitude: 4000,
    category: "first"
  },
  { location: "West",
    amplitude: 300,
    category: "first"
  },
  { location: "East",
    amplitude: 400,
    category: "second"
  },
  { location: "West",
    amplitude: 3000,
    category: "second"
  }
]

I use one series which I group by 'category':

Which produces the following chart:

Now I'd like to change the order of the categories, to instead be this:

The way I got to this was to split up into two series and filter by the group, like this:

Is there a way of reordering groups without splitting them into different series in a stacked bar chart? I'd like the simplicity of the first approach (using Group By to represent different groups) with the outcome of the second (ability to reorder by splitting groups into different series).

Thanks!

Hello @Lychee

modify your data to include a new " order " field and assign a unique order number to each category.

Additionally, ensure that the data is sorted by the "order" field in the data source.

Thank you!

1 Like

Thanks a lot for your help, this works. I'm going to keep using two different series, since I don't really like having to restructure my data queries for simple presentation reasons, but thanks for the suggestion!

1 Like