1

I have average values in the data stored in an array. Based on these average values, does CartoDB have functionality to fill the polygons in different color?Like if I give minimum and maximum values of average in a function it should fill colors automatically.

I am sure it can be done using the CartoDB editor. Can this be done using the CartoDB APIs?

1

Right now you would have to build the ramp quite manually, but CartoDB has some functions that they internally use to get these "breaks" in the ramps.

Here you have them:

From these functions you will get the break values that you can then use into your CartoCSS in order to set the color ramps.

All these functions obtain as a parameter the number of breaks that you want to have, so you can have a CartoCSS skeleton in which you set up the colors and styles for a certain amount of breaks, and then you can fill the categories with the output obtained from the functions above.

For example, imagine you do a SELECT via SQL API to one of those functions, with your column and the number of breaks (let's say 3), then, you could populate the following CartoCSS with Javascript (by concatenating strings) once you have the values:

#tablename{
  marker-fill-opacity: 0.8;
  marker-line-color: #FFF;
  marker-line-width: 1;
  marker-line-opacity: 1;
  marker-width: 10;
  marker-fill: #FFEDA0;
  marker-allow-overlap: true;
}
#tablename [ COLUMN_NAME <= BREAK_3] {
   marker-fill: #F03B20;
}
#tablename [ COLUMN_NAME <= BREAK_2] {
   marker-fill: #FEB24C;
}
#tablename [ COLUMN_NAME <= BREAK_1] {
   marker-fill: #FFEDA0;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.