top of page

Highlight Max and Min values in Line chart

Sometimes line chart contains more value points and it wont be readable if we enable the value labels. But it would be a nice feature to highlight minimum and maximum value in the chart to get a better understanding of value range in it. Here is a script to achieve this.



Steps:


  1. Create line chart and disable value label from design panel

  2. Add below widget script

  3. Save the script and refresh widget


widget.on('processresult', function(se, ev){ 
	
	let maxItem = Math.max.apply(Math, ev.result.series[0].data.map(function(el) { return el.y; }))
	let minItem = Math.min.apply(Math, ev.result.series[0].data.map(function(el) { return el.y; }))
	
	let maxfilterItems = ev.result.series[0].data.filter(el=>el.y == maxItem)
	let minfilterItems = ev.result.series[0].data.filter(el=>el.y == minItem)

	$.each(maxfilterItems, function(index, value){
		value.dataLabels = {
			enabled:true,
			borderColor: 'green',
			backgroundColor:'green',
			color: 'white',
			borderWidth: 1,
			borderRadius:3,
			padding: 3,
			style: {
				fontWeight: 'bold'
			}
		}
	
	})
	
	
	$.each(minfilterItems, function(index, value){
		value.dataLabels = {
			enabled:true,
			borderColor: 'red',
			backgroundColor:'red',
			color: 'white',
			borderWidth: 1,
			borderRadius:3,
			padding: 3,
			style: {
				fontWeight: 'bold'
			}
		}
	
	})
	
	
})

1 comentario

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación
Invitado
11 mar

This would be really useful, but unfortunately, it no longer works for a line chart that uses a dimension changer for the x-axis. Do you have any suggestions on how I can make it work, especially if I want to integrate it into a line chart where the date aggregation changes?

Me gusta
BI Next Level white logo

BI Next Level is your trusted resource for BI customization, data solutions, and expert insights. Explore practical tips, scripts, and tutorials for tools like Sisense, Python, and SQL. Let’s transform your data into impactful insights together.

Quick Links
Connect with us
Copyright © 2024. All Rights Reserved. Designed, Developed & Maintained  by Intertoons
bottom of page