top of page

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

});

223 views2 comments

2 bình luận

Đã xếp hạng 0/5 sao.
Chưa có xếp hạng

Thêm điểm xếp hạng
garrett
11 thg 1, 2023

Awesome! Thank you. This seems to break down on a stacked bar chart when switching to sort by value.

Thích
BI Next Level
BI Next Level
12 thg 1, 2023
Phản hồi lại

Use below script for stacked charts


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].categoriesSorting = 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].categoriesSorting = 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].categoriesSorting = 'asc'

widget.metadata.panels[0].items[0].jaql.sort = undefined

widget.refresh();

})

.add();

chart.renderer.button('Sort by…


Thích
bottom of page