top of page

Sort bar/columns/breakby manually

Updated: Nov 27, 2024


ree


This script is to sort items in X-axis manually. Widget will display bar/columns in the order you specified in 'categories' list


var categories= ['Jan','Feb','Mar','Apr','May','Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
widget.on('queryend',function(se,ev){
	ev.rawResult.values.sort(function(a, b){
		var aIndex = categories.indexOf(a[0].data);
		var bIndex = categories.indexOf(b[0].data);
						
		if (aIndex < bIndex)
			return -1;
		if (aIndex > bIndex)
			return 1;
							
		return 0;
	})
})


If you need to sort items in 'Break by', use below script


breakby = ['West', 'Midwest', 'South', 'Northeast', 'Unknown']
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;
	});
})



Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

BI Next Level is your trusted resource for BI customization, data solutions, and expert insights. Explore practical tips, scripts, and tutorials for tools like Sisense, Python, and SQL. Let’s transform your data into impactful insights together.

Quick Links
Connect with us
bottom of page