Scroll

Action Event: Conditional Region Coloring in GeoCharts

This Action Event can be used to modify the scaling of GeoCharts in order to allow for the conditional coloring of regions. This event modifies the theme of a GeoChart visualization, allowing it to simulate conditional coloring through color scaling.

Function: Custom Code

Event Type: Load

Global Event Type: None

Assigned UI Item(s): [None]

 

Custom Code Example

Language: C#

References: [None]

Namespaces: [None]

sessionInfo.JavascriptAction.SetJsCode(@"
let mapInfo = clientInfo.internal.geochartWidget;

// All possible values, in scale order
var allValues = [""0"", ""1"", ""2"", ""3""];

// Colors that correspond to the scale values (in the same order as allValues)
var scaleColors = [""#E51919"",""#E4E519"",""#19E519"",""#19B3E5""];

// Values that we have seen so far in the data set
let valuesSeen = [];

// Look through the data set to see what value options there are
let innerBreak = false;
for (let i = 0; i < mapInfo.data.length; i++)
{
if (innerBreak)
break;

for (let j = 0; j < mapInfo.data[i].values.length; j++)
{
if (valuesSeen.indexOf(mapInfo.data[i].values[j]) == -1)
{
valuesSeen.push(mapInfo.data[i].values[j]);

// Check if we have seen all possible values
let valueMissing = false;
for (let k = 0; k < allValues.length; k++)
{
if (valuesSeen.indexOf(allValues[k]) == -1)
{
valueMissing = true;
break;
}
}

if (!valueMissing)
{
innerBreak = true;
break;
}
}
}
}

// Find the min scale value and max scale value that we have seen,
// then add the colors for all the values in between
let minValueIndex = allValues.length - 1;
let maxValueIndex = 0;
for (let i = 0; i < allValues.length; i++)
{
// Update our min/max values if we have seen the corresponding value
if (valuesSeen.indexOf(allValues[i]) == -1)
continue;
if (minValueIndex > i)
minValueIndex = i;
if (maxValueIndex < i)
maxValueIndex = i;
}

// Udpate the color list to match the values that we have seen
let newColors = [];
for (let i = minValueIndex; i <= maxValueIndex; i++)
newColors.push(scaleColors[i]);

if (newColors.length > 0)
mapInfo.colors = newColors;
");

return sessionInfo.JavascriptAction;

Hidden Article Information

Article Author
Exago Development
created 2019-03-13 20:58:43 UTC
updated 2019-05-16 20:31:01 UTC

Labels
conditional formatting, GeoCharts,
Have more questions? Submit a request