top of page

Target/Benchmark Line Based on Selected Filter

It is possible to add a benchmark/Target line to a chart using script. But there can be situations where we need to change the benchmark value dynamically based on selected filter. Here is a script to achieve this.


  1. Create Bar chart/ Column chart/ Line chart/ Area chart

  2. Add below script to widget

  3. Update the variable 'filterName' with name filter panel based on which the benchmark line should change

  4. Update the variable 'filterBenchmarkMapping' with mapping of filter item to benchmark value. If multiple items or no items selected, value of 'default' will be taken as value. So don't delete 'default' item from the list.

  5. Save the script and refresh the dashboard

widget.on('processresult', function(se, ev){
	let filterName = 'Region'
	let filterBenchmarkMapping = {
		'South': 100000,
		'West': 150000,
		'Midwest' : 200000,
		'default' : 250000
	let selectedItem = 'default'
	let selectedFilter  = se.dashboard.filters.$$items.find(el=>el.jaql.title == filterName) //for dashboard filter
	//let selectedFilter  = ev.widget.metadata.panels[3].items.find(el=>el.jaql.title == filterName) //for widget filter
	if(selectedFilter && selectedFilter.jaql.filter && selectedFilter.jaql.filter.members && filterBenchmarkMapping[selectedFilter.jaql.filter.members[0]])
		selectedItem = selectedFilter.jaql.filter.members[0]

	ev.result.yAxis[0].plotLines = [{
				color: '#2ec7b5',
				dashStyle: 'LongDash',
				width: 2,
				value: filterBenchmarkMapping[selectedItem],
				zIndex: 5,
				label : {
					text : 'Target'

92 views0 comments

Recent Posts

See All
bottom of page