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.
Steps:
Create Bar chart/ Column chart/ Line chart/ Area chart
Add below script to widget
Update the variable 'filterName' with name filter panel based on which the benchmark line should change
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.
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'
}
}]
})
Comments