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:
Create a bar/column/line/area chart
Add below script to widget
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();
});
Awesome! Thank you. This seems to break down on a stacked bar chart when switching to sort by value.