React Analytics Charts
Edit page
Home
Core Components
Charts Overview
Common Charts
Custom Charts
BarChartColumnChartGeoChartDescriptionUsagePropsEurope ExampleUnited States ExampleLineChartPieChartTableChart
Custom Dashboards and Standalone ChartsHow To Get An OAuth Client ID From GoogleCode of ConductMIT License

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";
<AnalyticsDashboard
authOptions={{ clientId }}
renderCharts={(gapi, viewId) => {
return (
<GeoChart
gapi={gapi}
query={{
metrics: "ga:sessions,ga:pageviews",
dimensions: "ga:country",
"start-date": `28daysAgo`,
"end-date": "today",
ids: viewId,
}}
container="traffic-geo-chart"
/>
);
}}
/>

Props

PropTypeDescription
gapiGoogleAnalyticsEmbedAPIRequired. The ready and authorized Google Analytics Embed API
containerstringRequired. Provide an ID for the div that will contain the chart.
queryQueryRequired. The Query for the Analytics data. See the Query Prop section of DataChart.
optionsGeoChartOptionsOptional. 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:

OptionTypeDescription
regionstringThe area to display on the geochart. (Surrounding areas will be displayed as well.)
Can be one of the following:
  • world - A geochart of the entire world.
  • A continent or a sub-continent, specified by its 3-digit code, e.g., 011 for Western Africa, or a region alias such as europe.
  • A country, specified by its ISO 3166-1 alpha-2 code, e.g., AU for Australia.
  • A state in the United States, specified by its ISO 3166-2:US code, e.g., US-AL for Alabama. Note that the resolution option must be set to either provinces or metros.
Default: world
resolutionstringThe resolution of the geochart borders.
Choose one of the following values:
  • countries - Supported for all regions, except for US state regions.
  • provinces - Supported only for country regions and US state regions. Not supported for all countries; please test a country to see whether this option is supported.
  • metros - Supported for the US country region and US state regions only.
Default: countries
widthnumber | stringWidth 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.
heightnumber | stringHeight of the chart, in pixels.
keepAspectRatiobooleanIf 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:

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.

AliasCodeAreaSupported
world001World✔️ (world only)
africa002Africa✔️
northern-africa015Northern Africa✔️
sub-saharan-africa202Sub-Saharan Africa
eastern-africa014Eastern Africa✔️
middle-africa017Middle Africa✔️
southern-africa018Southern Africa✔️
western-africa011Western Africa✔️
americas019Americas✔️
latin-america-caribbean419Latin America and the Caribbean
caribbean029Caribbean✔️
central-america013Central America✔️
south-america005South America✔️
north-america003North America
northern-america021Northern America✔️
asia142Asia✔️
central-asia143Central Asia✔️
eastern-asia030Eastern Asia✔️
south-eastern-asia035South-eastern Asia✔️
southern-asia034Southern Asia✔️
western-asia145Western Asia✔️
europe150Europe✔️
eastern-europe-northern-asia151Eastern Europe (including Northern Asia)✔️
northern-europe154Northern Europe✔️
southern-europe039Southern Europe✔️
western-europe155Western Europe✔️
oceania009Oceania✔️
australia-and-new-zealand053Australia and New Zealand✔️
melanesia054Melanesia✔️
micronesia057Micronesia✔️
polynesia061Polynesia✔️

Europe Example

The following uses the europe alias for UN M49 code 150:

<AnalyticsDashboard
authOptions={{ clientId }}
dashId="europe"
renderCharts={(gapi, viewId) => {
return (
<GeoChart
gapi={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:

<AnalyticsDashboard
authOptions={{ clientId }}
dashId="usa"
renderCharts={(gapi, viewId) => {
return (
<GeoChart
gapi={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",
}}
/>
);
}}
/>