2

CartoDB allows the user to change the legend values for the left label and the right label. However, I would like to add values to the three middle color values. Is there a way to do use within the the CSS or SQL options in CartoDB?

Alternatively, CartoDB allows the user to select 3, 5 or 7 buckets to define the color intensity for a group of values. Is it possible for the color ramp to be on a continuous scale? I.e. the color of each polygon isn't allocated to one of the 3, 5, or 7 colors but rather is determined based on where the value falls within the entire value range?

enter image description here

2 Answers 2

1

You can customize the legend by clicking that little </> button in the upper right of your included image, which lets you edit the HTML of the legend widget. (Note: Making legend changes in the wizard afterward may overwrite your custom changes, so copy them to a Notepad file or elsewhere if you plan on tinkering with it further.)

Using HTML and inline CSS, you can then add additional colors (and use colors outside the presets) and custom intervals/labels.

It does get a bit messy because you have to interact with the default CartoDB styles for the legend. For complete control over the look, you can use CartoDB.js instead of the CartoDB editor.

2
  • Thank you Brandon. Very helpful. Do you also have any advise to the second part of my question: how can one create a progressive color ramp rather than having to use 3, 5, or 7 buckets. Could you suggest code to insert into the HTML widget?
    – Danny
    Aug 20, 2015 at 21:18
  • Iriberri's code is a great example. You can add more colors the same way, but make sure you add the corresponding colors and their value ranges to the CartoCSS section too -- otherwise your legend will be a liar! As for like an automatic gradient/progressive ramp, I'm not aware of a way to do that.
    – Brandon
    Aug 21, 2015 at 14:02
1

Perhaps the custom legend I'm showing in this map is useful for you: http://bl.ocks.org/iriberri/5b2c5b9001b48ee11f7e

Image legend

The code is as follows (notice you can copy&paste it in the custom HTML option for legends in the CartoDB Editor):

<div class='cartodb-legend density'>  
<ul>
  <li class="min">
  Percent %
  </li>

  <li class="graph leg" style="border-radius: 0; border:none">
  <div class="colors">
    <div class="quartile" style="background-color:#FFFFB2"></div>
    <div class="quartile" style="background-color:#FECC5C"></div>
    <div class="quartile" style="background-color:#FD8D3C"></div>
    <div class="quartile" style="background-color:#F03B20"></div>
    <div class="quartile" style="background-color:#BD0026"></div>
  </div>
    <div class="colors" style="font-weight:normal; text-align: center">
    <div class="quartile" style="padding-top: 5px" >[0-20]</div>
    <div class="quartile" style="padding-top: 5px" >[20-40]</div>
    <div class="quartile" style="padding-top: 5px" >[40-60]</div>
    <div class="quartile" style="padding-top: 5px" >[60-80]</div>
    <div class="quartile" style="padding-top: 5px" >[80-100]</div>
  </div>
  </li>
</ul>
</div>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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