top of page

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

Buttons to Sort bars/columns

Sorting is very simple in Sisense. But this option is accessible only by chart editors. We can add buttons to sort the chart by name or value using below script so that even viewers can sort the chart.


Steps:

  1. Create a bar/column/line/area chart

  2. Add below script to widget

  3. Save the script and refresh the widget



widget.on('processresult', function(se, ev){	
	ev.result.chart.spacing = [60, 20, 20, 20]
});


widget.on("domready", function(w, args){
		
	chart = w.chart[0][Object.keys(w.chart[0])[0]].hc
		
	chart.renderer.button('Sort by Name - Asc', 10, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = undefined
			widget.metadata.panels[0].items[0].jaql.sort = 'asc'
			
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Name - Desc', 150, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = undefined
			widget.metadata.panels[0].items[0].jaql.sort = 'desc'
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Value - Asc', 290, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = 'asc'
			widget.metadata.panels[0].items[0].jaql.sort = undefined
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Value - Desc', 430, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = 'desc'
			widget.metadata.panels[0].items[0].jaql.sort = undefined
			widget.refresh();
		})
		.add();

});


21 views2 comments

Recent Posts

See All
bottom of page