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.

Avoid data sorting in Donut chart

See original GitHub issue

I am submitting a…

  • Feature request
  • Design defect
  • Source code defect
  • Demo/documentation defect
  • Other

charts version:

    "@carbon/charts": "^0.41.30",
    "@carbon/charts-react": "^0.41.30",
    "carbon-components": "^10.22.0",
    "carbon-components-react": "^7.22.0",

Issue description

Donut chart is sorting my data, I want to avoid that

Steps to produce the issue

Create a Donut chart where options have a specific order. Click here to see an example.

Current behavior

It sorts the data by decreasing order.

Expected behavior

It should render the data in the order I give them to it. Or at least provide an option to behave like that.

Screenshot or recording

Screenshot 2021-02-04 at 12 48 22

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
theiliadcommented, Mar 19, 2021

I think I’m facing the same issue. Starting from 12 o’clock the the order of the pieces should be specifiable, or at least implement a coherent default order, for exemple, in the picture case I always want to see the same order in every Donut to keep it coherent

I’ll make sure that design responds to this soon

1reaction
ntsdcommented, Jun 6, 2021

I made a PR https://github.com/carbon-design-system/carbon-charts/pull/1043 to add sortFunction option for the pie chart (also work on Donut chart)

this can fix the issue by replacing the sort function

Examples

sort by reversed value

option: {
	pie: {
      sortFunction: (a: any, b: any) => {
		return b.value - a.value; // sort by reversed value
      },
    },
}

sort by name

option: {
	pie: {
      sortFunction: (a: any, b: any) => {
		return a.group.localeCompare(b.group); // sort by name
      },
    },
}

sort by group order

const groupOrders = ['group1', 'group2'];

.
.
.

option: {
	pie: {
      sortFunction: (a: any, b: any) => {
		return groupOrders.indexOf(a.group) - groupOrders.indexOf(b.group);  // sort by group orders
      },
    },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

prevent d3 donut chart from sorting automatically
Is there a way to prevent a donut chart from sorting values automatically? I don't see anywhere where I have specified that values...
Read more >
Avoid grouping in Pie or Donut chart
Solved: Hi, I have a requirement as "I have 10 rooms as Room A, Room B, Room C etc., based on the time...
Read more >
A Complete Guide to Pie Charts | Tutorial by Chartio
Avoid distorting effects​​ Reading a pie chart accurately requires that the slices' areas, arc lengths, and angles all point to an accurate representation...
Read more >
Excel Charts: Sorted Bar Chart as Alternative to the Pie Chart
The reputation of pie charts has majorly dropped in the past years. For good reason too.How can you make better graphs than the...
Read more >
Dos and don'ts of data visualisation — European Environment ...
Bar chart: do use the full axis and avoid distortion ... Pie charts: cons (and pros) ... Do sort your data for easier...
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