Select to view content in your preferred language

Arcade Code for Heat Chart

381
3
08-21-2023 09:04 AM
LaurenCammack01
New Contributor III

My end goal is to have a heat chart based on hour of day/day of week for calls for service. However, I have a filter on the date range so the color heat groups need to adjust as the data adjusts. I'm unable to figure out a way to gather all sum values and put in an array for me to get the max and min from the whole table. Below is where I'm at but I believe I need to somehow loop through the table using $rowindex? 

Thank you in advance!

// gather all sum values from chart to find max, min, and create 5 color groups
var myArray = [$datapoint.sum_Mon,$datapoint.sum_Tue,$datapoint.sum_Wed, $datapoint.sum_Thur, $datapoint.sum_Fri, $datapoint.sum_Sat, $datapoint.sum_Sun]
var groupDiff = (Max(myArray)-Min(myArray))/5
var groupTwo = groupDiff * 2 
var groupThree = groupDiff * 3
var groupFour = groupDiff * 4

function cellColor(callStatByDay){
  return When(callStatByDay < groupDiff, '#eecb9a',
                callStatByDay >= groupDiff && callStatByDay < groupTwo, '#e7b48f',
                callStatByDay >= groupTwo && callStatByDay < groupThree, '#e09d85',
                callStatByDay >= groupThree && callStatByDay < groupFour, '#d9867a', '#c06677' )
}   

return {
  cells: {
    Hour: {
      displayText : $datapoint.Hour,
      textColor: '',
      backgroundColor: '',
      textAlign: 'left',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Mon: {
      displayText : $datapoint.sum_Mon,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Mon),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Tue: {
      displayText : $datapoint.sum_Tue,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Tue),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Wed: {
      displayText : $datapoint.sum_Wed,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Wed),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Thur: {
      displayText : $datapoint.sum_Thur,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Thur),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Fri: {
      displayText : $datapoint.sum_Fri,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Fri),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Sat: {
      displayText : $datapoint.sum_Sat,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Sat),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    },
		
    sum_Sun: {
      displayText : $datapoint.sum_Sun,
      textColor: '',
      backgroundColor: cellColor($datapoint.sum_Sun),
      textAlign: 'center',
      iconName: '',
      iconAlign: '',
      iconColor: '',
      iconOutlineColor: ''
    }
  }
}
LaurenCammack01_0-1692633736346.png

 

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

Advanced formatting evaluates per row, so there's not a good way of pulling in values from other rows.

If the data came in from the Data Expression, you could find the absolute min/max values and insert them as per-row attributes for the sake of calculating a cell color. But I don't think that will be dynamic in a way the responds to a filter. The only widgets that allow for interactive reference values are indicators, I believe.

- Josh Carlson
Kendall County GIS
0 Kudos
Brian_DesLauriers
New Contributor

Lauren, did you ever figure this out?  I am trying something similar.  Works great with defined integers.  I also would like it to be dynamic and tried this.

Brian_DesLauriers_1-1720114847748.png

It is a little off and I can't seem to dial it in.

 

0 Kudos
LaurenCammack01
New Contributor III

I have not figured this out, if you get your to work successfully please let me know! @jcarlson any suggestions?

0 Kudos