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

Button to Show/Hide value labels

Sometime the widget looks messy when we enable value labels. At the same time it would be good to enable it to analyze the chart easily. So let the end user enable to disable value labels as they required. Here is a script to add button to chart to show/hide value labels.





Steps:

  1. Create new widget - (line/bar/column/pie/area chart)

  2. Add below script to widget

  3. Save the script and refresh widget


displayValue = false

widget.on('processresult', function(se, ev){	
	ev.result.chart.marginTop= 60
	ev.result.plotOptions.series.dataLabels.enabled = displayValue
	ev.result.plotOptions.bar.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();
	
});


It is possible to change style of buttons by adding 'style' property in the script

25 views0 comments

Recent Posts

See All