For any support or more customized script, contact us -  binextlevel@gmail.com

Sort bar/columns/breakby manually




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;
	});
})



150 views0 comments

Recent Posts

See All