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

Replace X-axis labels in a widget

We sometimes need to rename X-Axis labels to make them more meaningful. For example, if we have month numbers in a database, we can utilize them in a widget and use script to replace them with their names.


STEPS:

  1. Create widget with required fields

  2. Add below script to widget

  • replace the variable 'panelName' with name of panel whose items needs to be replaced

  • replace the variable 'newItemMapping' with mapping of existing and new labels

3. Save script and refresh widget




newItemMapping = { '1':'Jan',
				  '2':'Feb',
				  '3':'Mar',
				  '4':'Apr',
				  '5':'May'
				}

widget.on("queryend", function(se, ev){
	
	var panelName = 'Day Number' //Items in this panel will be replaced with new items
	
	panelIndex = ev.rawResult.headers.indexOf(panelName)
	$.each(ev.rawResult.values, function(index, value){

		
		if(newItemMapping[value[panelIndex].text] != undefined)
		{
			value[panelIndex].data = newItemMapping[value[panelIndex].data]
			value[panelIndex].text = newItemMapping[value[panelIndex].text]
		}
	})	
})

87 views0 comments

Recent Posts

See All