cancel
Showing results for 
Search instead for 
Did you mean: 

manual sorting categories in Scatter Chart

zohebakber
9 - Travel Pro
9 - Travel Pro

Hi Team,

I want to manually sort the categories for the x axis in scatter chart.
Please help.

Thanks

2 REPLIES 2

Sijo1995
9 - Travel Pro
9 - Travel Pro

Hi @zohebakber ,

Please try this script

var xOrder = 'asc' //also, this value can be desc
var yOrder = 'asc'

widget.on('beforeviewloaded', function(scope, args) {
    var shouldBeExecuted = (order === 'desc' || order === 'asc' )
    if (args.widget.type !== 'chart/scatter' || !shouldBeExecuted) {
        return
    }

    var daysOrder = args.options.xAxis.categories.sort();
    if (xOrder === 'desc') {
        daysOrder.reverse()   
    }


    if (daysOrder.length === args.options.xAxis.categories.length) {
        args.options.xAxis.categories = daysOrder
        for (i=0; i<daysOrder.length; i++) {
            for (k=0; k<args.options.series.length; k++) {
                for (j=0; j<args.options.series[k].data.length; j++) {                    
                    if (args.options.series[k].data[j].selectionData[0] === daysOrder[i]) {
                        args.options.series[k].data[j].x = i;
                    }
                }
            }
        }
    }
})


widget.on('beforequery', function(se, ev) {
    ev.query.metadata.forEach(function(m) {
        if (m.wpanel && m.wpanel === 'y-axis') {
            m.jaql.sort = yOrder
        }
    })
})

 

Thanks

Sijo

Hi Sijo,

Thanks for the reply..
I tried the below script and it worked..

 

var categories= ['10+% lower','5-10% lower','2-5% lower','0-2% lower','0%','0-2% Higher','2-5% Higher','5-10% Higher','10+% Higher'];

widget.on('queryend',function(se,ev){
ev.rawResult.values.sort(function(a, b){
var aIndex = categories.indexOf(a[0].data.trim());
var bIndex = categories.indexOf(b[0].data.trim());

if (aIndex < bIndex)
return -1;
if (aIndex > bIndex)
return 1;

return 0;
})
})