cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic heat map for Gradient color in pivot

zohebakber
9 - Travel Pro
9 - Travel Pro

Hi Team,
I am creating a gradient heat map for pivot and using this script. But, this only works for the second column. I tried to tweak the var tag but it's not working, can anyone help me with this.

Thank you

cc: @harikm007 

 

zohebakber_0-1676275471972.png

 



// select color theme from --> https://github.com/d3/d3-scale-chromatic
var colorTheme = 'interpolateYlGn';
var leftColorIntensity = 0.1;
var rightColorIntensity = 0.9;
widget.on("ready", function (w, args) {
$.getScript('https://d3js.org/d3.v5.min.js', function (data, textStatus) {
var tags = $('.table-grid__cell--col-parent-sibling-last', element);
var maxValue = 0.0;
var minValue = 0.0;
//debugger;
for (var i = 0; i < tags.length; i++) {
let tagText = tags[i].textContent;
let parseVal = parseFloat(tagText);
if (parseVal && parseVal > maxValue) {
maxValue = parseVal;
}
if (parseVal && parseVal < minValue) {
minValue = parseVal;
}
}
myScale = d3.scaleLinear()
.domain([minValue, maxValue])
.range([leftColorIntensity, rightColorIntensity]);
for (var i = 0; i < tags.length; i++) {
let tagText = tags[i].textContent;
let parseVal = parseFloat(tagText);
let colorValue = 0.0;
if (parseVal) {
colorValue = parseVal;
let scaled = myScale(colorValue);
tags[i].style.backgroundColor = d3[colorTheme](scaled);
}
}
});
});


1 ACCEPTED SOLUTION

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @zohebakber ,

Try replacing the line

var tags = $('.table-grid__cell--col-parent-sibling-last', element);

with

var tags = $('.table-grid__cell--col-parent-sibling-even,.table-grid__cell--col-parent-sibling-odd', element);

-Hari

 

View solution in original post

4 REPLIES 4

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @zohebakber ,

Try replacing the line

var tags = $('.table-grid__cell--col-parent-sibling-last', element);

with

var tags = $('.table-grid__cell--col-parent-sibling-even,.table-grid__cell--col-parent-sibling-odd', element);

-Hari

 

Hi Hari,

Yes, I figured this out.
Thank you so much..

Netser
7 - Data Storage
7 - Data Storage

Hi , 

for some reason this script doesn't work for me at all, is there any pre requisite ?  

Hello @harikm007 is there a way to exclude grand total values? Thank you!