cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
In order to sort both axes in the Scatter chart you might need to use the following script under the "Widget Script" level
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
        }
    })
})
Rate this article:
Comments
sisense-admin
7 - Data Storage
7 - Data Storage

Thanks! How would I do this if I wanted to do a custom sort? For example, the ascending and descending order alphabetically don't achieve what I want, and I want the order to specifically be a,c,b,d.

Version history
Last update:
‎03-02-2023 09:12 AM
Updated by:
Contributors