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:
Create new widget - (line/bar/column/pie/area chart)
Add below script to widget
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
Comentarios