Forum Discussion

Jack_Machesky's avatar
Jack_Machesky
Cloud Apps
02-01-2024
Solved

Bar Chart Label Order

I was wondering if anyone has a solution to re ordering the labels of a bar chart widget to a custom order. It seems the bars are labeled in alphabetical order, and I would like to change the order of them around. Let me know if you have any ideas, thanks.

2 Replies

Replies have been turned off for this discussion
  • Liliia_DevX's avatar
    Liliia_DevX
    Sisense Employee

    Jack_Machesky hi! Please review this custom plugin that might help to achieve your goal: Custom Bar/Column Chart Plugin (Show Totals, Sort Categories, Sort Breakbys)

    Important note: the provided solution is not an official feature and is not supported or goes through the proper product life cycle. This will require maintenance and proper testing on your side and I also highly recommend running on a staging environment before upgrading or implementing it on production environments.

    Best, Lily

  • zach_myt's avatar
    zach_myt
    Data Pipeline

    On a stacked bar chart you can use the below script to define the order

    const breakby = ['category_name1', 'category_name2', 'category_name3'];
    widget.on('processresult', function(se, ev) {
    ev.result.series.sort(function(a, b) {
    if (breakby.indexOf(a.name) < breakby.indexOf(b.name)) {
    return -1;
    } else if (breakby.indexOf(a.name) > breakby.indexOf(b.name)) {
    return 1;
    }
    return 0;
    });

    ev.result.legend.reversed = false;
    });