Showing results for 
Search instead for 
Did you mean: 

Sorting Chart By Different Field Than The One Displayed

8 - Cloud Apps
8 - Cloud Apps

I have a column chart that is currently displaying events on the x-axis (through an "eventCode field), and they are appearing automatically in descending order by the "total competitors" (displayed on the y-axis). I would like to sort and display the events on the x-axis instead by an "eventKey" field that is also in the Data Model. Is it possible to sort chart axis labels by a different field? Basically, I want to be able to replicate the custom sort configuration (see attachment) that is offered on the Sisense website in compose sdk.



11 - Data Pipeline
11 - Data Pipeline

Hello @ewoytowitz 

The script provided below enables you to sort the x-axis of a column chart based on another field.

Ensure to modify the variable 'newJaql' with the specific field details by which you want to sort, in your case, it's 'eventKey' and its corresponding table. Additionally, ensure that no two event codes have the same eventKey.


var newJaql = { jaql:{
			column: "Category ID",
			datatype: "numeric",
			dim: "[Category.Category ID]",
			merged: true,
			table: "Category",
			title: "ranking_field"
widget.on("beforequery", function (se, ev) {




	categoryPanelName = se.metadata.panels[0].items[0].jaql.title

	categoryResultIndex = ev.rawResult.headers.indexOf(categoryPanelName)
	rankingResultIndex = ev.rawResult.headers.indexOf(newJaql.jaql.title)

	var item_list = [];

	$.each(ev.rawResult.values, function(index, value){
		if(!(value[categoryResultIndex].text in item_list))
			item_list[value[categoryResultIndex].text] = (value[rankingResultIndex].data == 'N\\A' ? -1 : value[rankingResultIndex].data)

	ev.rawResult.values.sort(function(a, b){
		var aIndex = item_list[a[0].data];
		var bIndex = item_list[b[0].data];

		if (aIndex < bIndex)
			return -1;
		if (aIndex > bIndex)
			return 1

			return 0;



Feel free to reach out if you have further questions, we're always happy to help 🙂
[email protected] 
Paldi Solutions, Number #1 Sisense Plugins Developer