I'm trying to dynamically set my Carto map's dot colors based on a JavaScript variable.
var queryAllRows= "SELECT+" + colNames.join(',') + "+FROM+MY_TABLE_NAME";
queryAllRows= queryAllRows.replace(' ','+')
var queryAllRowsURL="https://ACCOUNT_NAME.carto.com/api/v2/sql?q=" + queryAllRows + "&api_key=" + apiKey;
var sums= [];
$.getJSON(queryAllRowsURL, function(queryResult){
// The point of this loop is to find the highest number in `rowObj`.
// Each `rowObj` elements looks something like this...
// {city: "New York", score1: 10, score2: 20}
for (var i=0; i < queryResult.rows.length; i++) {
var rowObj= queryResult.rows[i];
sums.push(sumOfObjElements(rowObj)); // This line sums up the numbers in the object, pushes the sum into an array
}
var highestScore= Math.max.apply(Math, sums);
});
Each dot on my map is a city. I want to sum get the sum of each city's score, divide it by highestScore
, and set the dot color based on that result.
How do I do this?