cancel
Showing results for 
Search instead for 
Did you mean: 
rapidbisupport
11 - Data Pipeline
11 - Data Pipeline

Custom sort for Bar and Column Chart

Question:

I have seen several posts of people asking if there is a simple way to apply custom sorts for car and column charts, and until recently, I have been using the community customBarColumnChart Plugin, which is not supported anymore, and also not working correctly in the latest version of Sisense cloud. Not sure why this cannot become a standard feature within the system, as there seem to be a lot of requests for this functionality.   

Answer: 

The following widget scripts will allow you to sort categories in a bar/column chart. You can change the order of items in sortOrder to change the order. They cater to when you want to sort by a Break By, or when you want to sort by Categories with no Break By.

BREAK BY:

 

widget.on('processresult', (w, args) => {
  var sortOrder = ['Yellow', 'Black', 'Red', 'Blue ', 'Gold', 'Silver']
  args.result.series.sort(function (a, b) {
    return sortOrder.indexOf(a.name) - sortOrder.indexOf(b.name)
  })
})

 

The configuration is also attached in a screenshot below:

rapidbisupport_0-1723129641624.png


CATEGORIES:

If you're aiming to sort by the Categories directly, then you can use the following instead:

 

widget.on('processresult', (w, args) => {
  var sortOrder = ['USA', 'Europe']
  args.result.series[0].data.sort(function (a, b) {
    return sortOrder.indexOf(a.selectionData[0]) - sortOrder.indexOf(b.selectionData[0])
  })
  args.result.xAxis.categories.sort(function (a, b) {
    return sortOrder.indexOf(a) - sortOrder.indexOf(b)
  })
})

 

This configuration looks like this:

rapidbisupport_1-1723129724930.png

This was tested using Sample Retail.

Let me know how it goes for you in the comments!  

Check out this related content: 
Academy
Documentation

Rate this article:
Comments
wallingfordce
10 - ETL
10 - ETL

I have similar need, but as a workaround to what looks like a defect. I'm using a numeric value as the Break by, which sorts as expected in the Break by panel list of members. But in the widget output and legend, it's sorting alphabetically. I cannot know or list out all the members of the field used in the Break by. Can a version of your script here be used to force the sort to be numeric 

wallingfordce_0-1731536273549.png

 

Jake_Raz
10 - ETL
10 - ETL

@wallingfordce Maybe try this script? If you have a break-by then it sorts the members dynamically from largest to smallest (dynamically, as-in: you don't have to manually specify each particular value). This also changes the order in which they're displayed in the legend.

Jake_Raz_0-1732196510488.png

 

wallingfordce
10 - ETL
10 - ETL

Thanks for that @Jake_Raz,

I really appreciate you trying to get me on the right track. 

The linked script sorts the Break by members by their respective Value result. I'm hoping to sort by the same numeric description that is shown in the Break by panel for the field.

wallingfordce_0-1732204545057.png

 

Version history
Last update:
‎09-05-2024 08:32 AM
Updated by: