Still have questions?
Contact support

Map Legend


AnyMap legend works the same way it works in all other chart types. Look through Legend Settings article for more information about legends:

This articles shows several samples how legend is used with AnyChart JavaScript maps.

Simple Legend

Legend is used predominantly to show names of the regions on a map and some side values that describes this series at some point (like sales amount, divorce rate, etc.).

In the sample below we display the map of the USA (colored states are states where ACME Corp. sells its goods) with a legend that displays a list of states and sales volume for each of them.

JsFiddle Playground

  // series setting
  var series = map.choropleth(dataSet);
  series.hoverFill('#FF9933');'Sales of ACME Corp.');
  series.colorScale(anychart.scales.linearColor('#E08529', '#753D05'));
  // some legend settings

Note that this series is colored using the colorScale and the color of the state depends on the value it represents. We have changed the legendItem icon from default rectangular to circle using iconType().

Multiple Legends

Multiple Legends might be useful when you need to show different data in one map. In the sample below we add the second legend, which regions represent those states where the expansion is planned.

JsFiddle Playground

Note that the Color Range is also used in the sample, read more about it in Color Range article.

Thresholds in Legend

You can use Legend with thresholds; with thresholds, the legend looks similar to a Color Range with an ordinal Color Scale.

Let's create one more data set and a legend for it and define another color scale. This new series tells us about rival companies average profit.

var series_other = map.choropleth(dataSet_other);
series_other.geoIdField('iso_3166_2');'Sales of other companies');
  return (this.value);
series_other.tooltip().contentFormatter(function() {
  return '<span style="font-size: 13px">' + '$ ' + this.value + 'm </span>';
var scale = anychart.scales.ordinalColor([
  {less: 5},
  {from: 5, to: 10},
  {greater: 10}
scale.colors(['#73E6BF', '#54D1B5', '#26B2A6']);
// legend settings
var legend = map.legend();

JsFiddle Playground

Undefined Regions In Legend

If you've got a lot of undefined regions (regions with no data), but you need to color them, use the unboundRegions() method:

// set the color for undefined (unbound) regions

JsFiddle Playground