This page describes how to create a colored map using the Charts API. This chart
is a new, improved version that supports a larger map and more features than the older
map chart (cht=t
).
Table of Contents
Chart-Specific Features |
Standard Features
|
Overview
You can create a map with various countries or states highlighted in custom colors. You can let the map zoom to the proper level to display your selected countries properly, or you can zoom in or out to a custom level using latitude and longitude values.
Supported Parameters
Map charts support the following parameters:
Parameter | Required or Optional | Description |
---|---|---|
cht=map<opt_zoom_and_center> |
Required | Specifies a map chart. opt_zoom_and_center - An optional string that enables you to zoom or center the chart on a specific region. See details. |
chs |
Required | Map size. Maximum dimensions for a map are 600 pixels wide, 600 pixels high, or 300,000 pixels total. |
chd= |
Optional | If used, the data value will indicate the color of the corresponding
country, along the color gradient specified by chco . |
chld= |
Required | A pipe-separated list of countries or states that will be highlighted
in colors specified by |
|
Optional | Chart colors. The format of this string depends on whether you use
|
chtt, chts |
Optional | Chart title and style |
chm |
Optional | Chart markers |
chma |
Optional | Chart margins |
chf=bg... |
Optional | Solid fills (background only) |
chdl |
Optional | Chart legends |
Examples
Description | Example | |||
---|---|---|---|---|
In this example:
|
|
|||
A map showing France, with two regions highlighted:
|
chld=FR-D|FR-B|FR |
|||
This map demonstrates using color gradients.
|
chd=t:0,50,100 |
|||
Note that the map can be cropped inside the specified chart size. This is because we will not distort a map to fit inside a specified chart size, but we limit the map to the regions that you specify in chld. Therefore, to avoid cropped regions inside the chart boundaries, you might have to adjust the map size manually. |
|
Zooming and Centering
By default, the chart will be zoomed and centered to center your selected regions, and make them fit into the rendered area as closely as possible, within the defined map size. However, you can customize the centering and zooming level of the chart in two different ways:
By pixel
To adjust the borders by pixel size, use this format:
cht=map:auto=<left_border>,<right_border>,<top_border>,<bottom_border>
Where each border size is the additional border to show, in pixels, beyond the automatically calculated zoom level.
You can only zoom out (positive values); you cannot zoom in (negative values) closer than the default zoom level using pixel zooming.
Examples:
These examples all show London (Lat
No Zooming (default) | Zoomed out 30 pixels per side | Zoomed out and down to the right |
---|---|---|
|
cht=map:auto=30,30,30,30 |
cht=map:auto=50,0,80,0 |
By Latitude and Longitude
You can specify the exact top, bottom, left, and right borders of the rendered map by latitude and longitude using the syntax shown here:
cht=map:fixed=<bottom_border_lat>,<left_border_long>,<top_border_lat>,<right_border_long>
Where <bottom_border_lat> and <top_border_lat> specify the latitude of the bottom and top borders, and <left_border_long> and <right_border_long> specify the longitude of the left and right borders.
Note: Because of Mercator projection distortion (basically, projecting a curved map onto a flat image), focusing on a tall, narrow strip can cause some unexpected size differences in your map.
Examples:
The following examples show London (highlighted in blue) which is 0.1° longitude, 51.5° latitude. Note how there is map cropping because the map is trying to display only Great Britain (as specified) and fill the designated chart without distortion.
Centered | Latitudes shifted +10* | Zoomed by reducing all values |
---|---|---|
cht=map:fixed=40,-10,60,10 |
|
cht=map:fixed=48,-3,54,3 |
Note how the size of the middle image is a bit smaller than the first image, even though we've moved the same number of degrees up. This is because we're projecting a 3-D sphere onto a 2-D image. You would have to increase the width of the second chart to make it the same size as the first chart.
Standard Features
The rest of the features on this page are standard chart features.