GeoChart
Description
A geo chart shows data on a geographical map. You can specify either the entire world or a specific region.
You can use this to create a custom chart by providing your own data query (see DataChart for more info on queries) and, optionally, geo chart options for the chart.
Refer to the Charts Overview for a list of all charts available.
Usage
import { AnalyticsDashboard, GeoChart } from "react-analytics-charts";
<AnalyticsDashboardauthOptions={{ clientId }}renderCharts={(gapi, viewId) => {return (<GeoChartgapi={gapi}query={{metrics: "ga:sessions,ga:pageviews",dimensions: "ga:country","start-date": `28daysAgo`,"end-date": "today",ids: viewId,}}container="traffic-geo-chart"/>);}}/>
Props
Prop | Type | Description |
---|---|---|
gapi | GoogleAnalyticsEmbedAPI | Required. The ready and authorized Google Analytics Embed API |
container | string | Required. Provide an ID for the div that will contain the chart. |
query | Query | Required. The Query for the Analytics data. See the Query Prop section of DataChart. |
options | GeoChartOptions | Optional. Options for the chart. To determine what to use here, refer to the Configuration Options section for geo charts. |
This component also supports all div
props, such as className
, style
, and onClick
.
If you have more than one of this chart on the page, be sure to specify a unique container
ID.
Query
Refer to DataChart Query Prop to build your own data query
.
Chart Options
There are numerous chart options available for
geo charts, allowing you to customize the appearance. Provide these via the options
prop.
Below are a few of the notable ones:
Option | Type | Description |
---|---|---|
region | string | The area to display on the geochart. (Surrounding areas will be displayed as well.) Can be one of the following:
world |
resolution | string | The resolution of the geochart borders. Choose one of the following values:
countries |
width | number | string | Width of the visualization, in pixels. The default width is 556 pixels, unless the height option is specified and keepAspectRatio is set to true - in which case the width is calculated accordingly. |
height | number | string | Height of the chart, in pixels. |
keepAspectRatio | boolean | If true , the geochart will be drawn at the largest size that can fit inside the chart area at its natural aspect ratio. If only one of the width and height options is specified, the other one will be calculated according to the aspect ratio. If false , the geochart will be stretched to the exact size of the chart as specified by the width and height options. Default true . |
The containing element is rendered as a div
and you can size and style it as you see fit using CSS.
Geo charts do not support titles. You'll have to add your own above the chart.
See all chart options.
Region Codes
The region
prop can take a variety of values, allowing you to chart different parts of the globe. You can use world
to show the whole world, or choose a code below:
- Use a region alias, or see the UN M49 Standard Country or Area Codes for Statistical Use for a list of region codes, such as
011
for Western Africa. - See ISO 3166-1 alpha-2 code for a list of country codes such as
AU
for Australia. - See ISO 3166-2:US for a list of codes for US States, such as
US-AL
for Alabama.
Region Aliases
Aliases are available for all UN M49 region codes. You can use an alias to make things a little more human readable.
Some codes are not supported by Google, but feel free to try them in case they've been added.
Alias | Code | Area | Supported |
---|---|---|---|
world | 001 | World | ✔️ (world only) |
africa | 002 | Africa | ✔️ |
northern-africa | 015 | Northern Africa | ✔️ |
sub-saharan-africa | 202 | Sub-Saharan Africa | ❌ |
eastern-africa | 014 | Eastern Africa | ✔️ |
middle-africa | 017 | Middle Africa | ✔️ |
southern-africa | 018 | Southern Africa | ✔️ |
western-africa | 011 | Western Africa | ✔️ |
americas | 019 | Americas | ✔️ |
latin-america-caribbean | 419 | Latin America and the Caribbean | ❌ |
caribbean | 029 | Caribbean | ✔️ |
central-america | 013 | Central America | ✔️ |
south-america | 005 | South America | ✔️ |
north-america | 003 | North America | ❌ |
northern-america | 021 | Northern America | ✔️ |
asia | 142 | Asia | ✔️ |
central-asia | 143 | Central Asia | ✔️ |
eastern-asia | 030 | Eastern Asia | ✔️ |
south-eastern-asia | 035 | South-eastern Asia | ✔️ |
southern-asia | 034 | Southern Asia | ✔️ |
western-asia | 145 | Western Asia | ✔️ |
europe | 150 | Europe | ✔️ |
eastern-europe-northern-asia | 151 | Eastern Europe (including Northern Asia) | ✔️ |
northern-europe | 154 | Northern Europe | ✔️ |
southern-europe | 039 | Southern Europe | ✔️ |
western-europe | 155 | Western Europe | ✔️ |
oceania | 009 | Oceania | ✔️ |
australia-and-new-zealand | 053 | Australia and New Zealand | ✔️ |
melanesia | 054 | Melanesia | ✔️ |
micronesia | 057 | Micronesia | ✔️ |
polynesia | 061 | Polynesia | ✔️ |
Europe Example
The following uses the europe
alias for UN M49 code 150
:
<AnalyticsDashboardauthOptions={{ clientId }}dashId="europe"renderCharts={(gapi, viewId) => {return (<GeoChartgapi={gapi}query={{metrics: "ga:sessions,ga:pageviews",dimensions: "ga:country","start-date": `28daysAgo`,"end-date": "today",ids: viewId,}}container="europe-traffic-geo-chart"options={{region: "europe",resolution: "countries",}}/>);}}/>
United States Example
The following uses the ga:region
dimension, the US
country code region, and the provinces
resolution to show traffic from individual states in the United States:
<AnalyticsDashboardauthOptions={{ clientId }}dashId="usa"renderCharts={(gapi, viewId) => {return (<GeoChartgapi={gapi}query={{metrics: "ga:sessions,ga:pageviews",dimensions: "ga:region","start-date": `28daysAgo`,"end-date": "today",ids: viewId,}}container="usa-traffic-geo-chart"options={{region: "US",resolution: "provinces",}}/>);}}/>