TransWikia.com

Adjust labels in CartoDB choropleth legend

Geographic Information Systems Asked on March 13, 2021

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

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.

Answered by Brandon on March 13, 2021

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>

Answered by iriberri on March 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP