Forum Discussion

harikm007's avatar
harikm007
Data Warehouse
07-27-2022

Add button to widget (to show/hide value labels, change widget type, open URL)

It is possible to add button(s) to widgets for various purposes like to change visualization type, show or hide value labels in chart, open a url and much more.

Below script is to add button to show/hide value labels in widget:

 

displayValue = false

widget.on('processresult', function(se, ev){	
	ev.result.chart.marginTop= 60
	ev.result.plotOptions.series.dataLabels.enabled = displayValue
	ev.result.plotOptions.line.dataLabels.enabled = displayValue
});

widget.on("domready", function(w, args){
	
	chart = w.chart[0][Object.keys(w.chart[0])[0]].hc
	chart.renderer.button(
		displayValue == true?'Hide Values':'Show Values', 
		10, 
		10)
		.on('click', function () {
			displayValue = !displayValue
			widget.refresh();
		})
	.add();
	
});

 

Refer below posts for adding buttons for some other purposes:

Change widget type : https://www.binextlevel.com/post/button-to-change-widget-type

Open a page/URL: https://www.binextlevel.com/post/add-button-to-sisense-widget

 

-Hari