top of page

Display total value in legend - Bar/Column/Area/Line chart

A column chart splits the data by one or more dimensions and we have to manually sum up or create a separate widget to find total value of each dimensions.

The script below displays total value of each dimensions/items along with legend




Steps:

  1. Create a bar/column/line/area chart

  2. Add below script to widget

  3. Save the script and refresh widget


widget.on('processresult', function(se, ev){
	
	ev.result.legend.labelFormatter = function(){
		legendSeries = ev.result.series.find(el=>el.name == this.name)
		
		totalValue = 0
		$.each(legendSeries.data, function(index, value){
			totalValue = totalValue + value.y
		})
		
		myItem = se.metadata.panels[1].items[0]
		myMask = $$get(myItem, "format.mask", {})

		var numberFormatter = prism.$injector.get('$filter')('numeric');
		formattesValue = numberFormatter(totalValue, myMask);
		
		return this.name + '<span style="color:#838584; font-size:12.5px"> <b> (' + formattesValue + ')</b></span>'
	}
	
})

250 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page