cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Custom sort for Bar and Column Chart

francoisvv
8 - Cloud Apps
8 - Cloud Apps

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 seems to be a lot off requests for this functionality.    Any suggestions would be greatly appreciated!

1 ACCEPTED SOLUTION

rapidbisupport
10 - ETL
10 - ETL

Hi @francoisvv

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-1710400807836.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_0-1710401398226.png

This was tested using Sample Retail.

Let me know how you go?

Thanks,

Daniel

RAPID BI

[email protected]

RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons

View solution in original post

1 REPLY 1

rapidbisupport
10 - ETL
10 - ETL

Hi @francoisvv

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-1710400807836.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_0-1710401398226.png

This was tested using Sample Retail.

Let me know how you go?

Thanks,

Daniel

RAPID BI

[email protected]

RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons