question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🧐[How to sort stacked bar]

See original GitHub issue

Is there a way of sorting stacked bar ?

Let’s say I have the following configuration:

const config = {
    data: [
        {
            x: 40,
            y: "foo",
            color: "yellow"
        },
        {
            x: 2,
            y: "foo",
            color: "red"
        },
        {
            x: 40,
            y: "bar",
            color: "yellow"
        }
    ],
    isStack: true,
    xField: 'x',
    yField: 'y',
    seriesField: 'color',
    color: (_ref: any) => _ref.color
};

I get this chart: image

How can I get the red bar at the left ?

If I use .reverse(), I succeed to get the red bar at the left, but bar gets displayed before foo, which is not what I want image

If I use .reverse() and I reorder the inputed data (bar before foo), I get the same result as the first screenshot.

Any solution ?

Thanks for your help.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Lechevalliercommented, Apr 7, 2021

The second method is giving me the expected result, thanks!

So if I understand well, it is not only about adjusting data order, but as well about altering data array to make sure each y (foo & bar) has every kind of series (“yellow” & “red”), even if there is nothing to display (x: 0).

It could be good to write it somewhere in the documentation, or better, handle the case each y do not have every kind of series.

0reactions
lxfu1commented, Oct 17, 2022

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Sort a Stacked Bar Chart From High to Low in Chart JS
How to Sort a Stacked Bar Chart From High to Low in Chart JSSorting a stacked bar chart from high to low in...
Read more >
Tableau tip: How to sort stacked bars by multiple dimensions
1. Build your stacked bar chart in Tableau. · 2. Create a combined field using the dimensions you want to sort by. ·...
Read more >
How to sort stacked bars in Tableau | Edureka Community
1. Create a stacked bar chart. · 2. Here you can sort using 3 fields 2 from the axis and the the 3rd...
Read more >
How do you sort stacked bar chart by value - Question & Answer
The stacked groups in a Vertical stacked bar chart can be sorted alphabetically. However, I want to sort them by value where the...
Read more >
sort a normalized stacked bar chart with Altair - Stack Overflow
If you set the sort parameter in alt.Color() to either 'ascending' or 'descending' , it will sort the stacked bars automatically:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found