Forum Discussion
Hi wallingfordce ,
Please try the below script and let me know if you are looking for something like this:
widget.on('processresult', function(se,ev){
var colorMapping = {
'Level A': 'red',
'Level B': 'green',
'Level C': 'blue',
'Level D': 'yellow'
}
$.each(ev.result.series, function(seriesIndex, seriesValue){
$.each(seriesValue.data, function(index, value){
const categoryName = value.selectionData[0];
first_part = categoryName.includes('-') ? categoryName.split('-')[0].trim() : categoryName;
second_part = categoryName.includes('-') ? categoryName.split('-')[1].trim() : categoryName;
value.color = {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, (first_part in colorMapping ? colorMapping[first_part] : 'gray')],
[1, (second_part in colorMapping ? colorMapping[second_part] : 'gray')]
]
}
})
})
})
- Hari
- wallingfordce05-19-2025Data Pipeline
Love that and looks like the right idea. Does it matter that I don't have a field on Categories or Break By, because I'm not seeing this have any effect, and throwing a console.log(categoryName) in there doesn't output anything.
- harikm00705-20-2025Data Warehouse
The script needs to be adjusted slightly if the Categories or Breakby fields are not present. Here's the updated version.
widget.on('processresult', function(se,ev){ var colorMapping = { 'Level A': 'red', 'Level B': 'green', 'Level C': 'blue', 'Level D': 'yellow' } $.each(ev.result.series, function(seriesIndex, seriesValue){ const seriesName = seriesValue.name; first_part = seriesName.includes('-') ? seriesName.split('-')[0].trim() : seriesName; second_part = seriesName.includes('-') ? seriesName.split('-')[1].trim() : seriesName; $.each(seriesValue.data, function(index, value){ value.color = { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, stops: [ [0, (first_part in colorMapping ? colorMapping[first_part] : 'gray')], [1, (second_part in colorMapping ? colorMapping[second_part] : 'gray')] ] } }) }) })
-Hari
- wallingfordce05-20-2025Data Pipeline
Closer, and really appreciate it. Seems like it's stuck only returning the first seriesName for all series
logging seriesName to console right after it's set each time shows all the different series names, but logging it inside the seriesValue.data loop logs the first series name every time.