2. set_map_source method: set_map_source(map_src, jsonp_map = False) map_src is the url (https) where map data is located, it is recommended to get map data from highcharts' map collection: https://code.highcharts.com/mapdata/ jsonp_map is boolean parameter if mapdata is loaded from jsonp geojson (from jsonp) or .js are accepted formats. default is javascript (.js) format (from highcharts) The following example is from Highmaps Demos GeoJSON areas: http://www.highcharts.com/maps/demo/geojson """ from highcharts import Highmap H = Highmap(width = 650, height = 500) options = { # construct option dict 'chart' :{ 'renderTo' : 'container' }, 'title' : { 'text' : 'GeoJSON in Highmaps' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' }
# -*- coding: utf-8 -*- """ Highmaps Demos GeoJSON with rivers and cities: http://www.highcharts.com/maps/demo/geojson-multiple-types """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import json_loader, js_map_loader, geojson_handler H = Highmap() options = { 'title': { 'text': 'Highmaps from geojson with multiple geometry types' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' } }, } H.set_dict_options(options) map_url = 'http://www.highcharts.com/samples/data/australia.geo.json' geojson = json_loader(map_url) states = geojson_handler(geojson, 'map') rivers = geojson_handler(geojson, 'mapline') cities = geojson_handler(geojson, 'mappoint') specialCityLabels = { 'Melbourne': {
# -*- coding: utf-8 -*- """ Highmaps Demos Categorized areas: http://www.highcharts.com/maps/demo/category-map """ from highcharts import Highmap H = Highmap(width=650, height=500) options = { 'chart': { 'spacingBottom': 20 }, 'title': { 'text': 'Europe time zones' }, 'legend': { 'enabled': True }, 'plotOptions': { 'map': { 'allAreas': False, 'joinBy': ['iso-a2', 'code'], 'dataLabels': { 'enabled': True, 'color': 'white', 'formatter': "function () {\ if (this.point.properties && this.point.properties.labelrank.toString() < 5) {\ return this.point.properties['iso-a2'];\ }\ }",
# -*- coding: utf-8 -*- """ Highmaps Demos Detailed map, US counties: http://www.highcharts.com/maps/demo/us-counties """ from highcharts import Highmap from highcharts.highmaps.common import RawJavaScriptText H = Highmap() """ This example shows how to make the map of US unemployment rates at county level in April 2015 as the highmaps demo: http://www.highcharts.com/maps/demo/us-counties However, this example requires to do many things in javascript environment: 1. a JS function to get "mapline" data using highcharts geojson function: Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline') where highcharts.maps is to get map data loaded from http://code.highcharts.com/mapdata/countries/us/us-all-all.js 2. a JS function to change names of each data set using Highcharts.each 3. need to add datasets for maplines. however, the datasets are not defined in python, therefore they need to add using "RawJavaScriptText('[lines[0]]')" which unquote the python string '[lines[0]]' in javascript environment (from '[lines[0]]' to [lines[0]]) This is not a good way to generate this map with python-highcharts API but still use many javascript function The example us-counties-2.py shows how to do this in pure python environment """ options = { 'chart': { 'borderWidth': 1,
# -*- coding: utf-8 -*- """ Highmaps Demos Detailed map, US counties: http://www.highcharts.com/maps/demo/us-counties """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler H = Highmap() """ This example generates the same map as us-counties.py, but using functions in highmap_helper module to handle data in python environment completely """ options = { 'chart': { 'borderWidth': 1, 'marginRight': 50 }, 'title': { 'text': 'US Counties unemployment rates, April 2015' }, 'legend': { 'title': { 'text': 'Unemployment<br>rate', 'style': { 'color': "(Highcharts.theme && Highcharts.theme.textColor) || 'black'"
chart.addSeriesAsDrilldown(e.point, { name: e.point.name, data: data, dataLabels: { enabled: true, format: '{point.name}' } }); }); } this.setTitle(null, { text: e.point.name }); }""", } H = Highmap() """ Drilldown map requires an additional JS library from highcharts, which can be added using add_JSsource method Also, it needs a bootstrap CSS file, which is added using add_CSSsource method """ H.add_JSsource('http://code.highcharts.com/maps/modules/drilldown.js') H.add_CSSsource( 'http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown': item['properties']['hc-key']})
2. set_map_source method: set_map_source(map_src, jsonp_map = False) map_src is the url (https) where map data is located, it is recommended to get map data from highcharts' map collection: https://code.highcharts.com/mapdata/ jsonp_map is boolean parameter if mapdata is loaded from jsonp geojson (from jsonp) or .js are accepted formats. default is javascript (.js) format (from highcharts) The following example is from Highmaps Demos GeoJSON areas: http://www.highcharts.com/maps/demo/geojson """ from highcharts import Highmap H = Highmap(width=650, height=500) options = { # construct option dict 'chart' :{ 'renderTo' : 'container' }, 'title' : { 'text' : 'GeoJSON in Highmaps' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' }
# -*- coding: utf-8 -*- """ Highmaps Demos Map point with lat/long: http://www.highcharts.com/maps/demo/mappoint-latlon """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler H = Highmap(height=750) map_url = 'http://code.highcharts.com/mapdata/countries/gb/gb-all.js' geojson = js_map_loader(map_url) data = [{ 'name': 'London', 'lat': 51.507222, 'lon': -0.1275 }, { 'name': 'Birmingham', 'lat': 52.483056, 'lon': -1.893611 }, { 'name': 'Leeds', 'lat': 53.799722, 'lon': -1.549167 }, { 'name': 'Glasgow', 'lat': 55.858, 'lon': -4.259 }, { 'name': 'Sheffield', 'lat': 53.383611,
# -*- coding: utf-8 -*- """ Highmaps Demos Categorized areas: http://www.highcharts.com/maps/demo/category-map """ from highcharts import Highmap H = Highmap(width=650, height=500) options = { 'chart': { 'spacingBottom': 20 }, 'title' : { 'text' : 'Europe time zones' }, 'legend': { 'enabled': True }, 'plotOptions': { 'map': { 'allAreas': False, 'joinBy': ['iso-a2', 'code'], 'dataLabels': { 'enabled': True, 'color': 'white', 'formatter': "function () {\ if (this.point.properties && this.point.properties.labelrank.toString() < 5) {\ return this.point.properties['iso-a2'];\
set map directly to the input (geojson) data geojson is the map data in geojson format 2. set_map_source method: set_map_source(map_src, jsonp_map = False) map_src is the url (https) where map data is located, it is recommended to get map data from highcharts' map collection: https://code.highcharts.com/mapdata/ jsonp_map is boolean parameter if mapdata is loaded from jsonp geojson (from jsonp) or .js are accepted formats. default is javascript (.js) format (from highcharts) The following example is from Highmaps Demos GeoJSON areas: http://www.highcharts.com/maps/demo/geojson """ from highcharts import Highmap H = Highmap(width=650, height=500) options = { # construct option dict 'chart' :{ 'renderTo' : 'container' }, 'title' : { 'text' : 'GeoJSON in Highmaps' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' }
# -*- coding: utf-8 -*- """ Highmaps Demos GeoJSON with rivers and cities: http://www.highcharts.com/maps/demo/geojson-multiple-types """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler H = Highmap() options = { 'title' : { 'text' : 'Highmaps from geojson with multiple geometry types' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' } }, } H.set_dict_options(options) map_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=australia.geo.json&callback=?' geojson = jsonp_loader(map_url) states = geojson_handler(geojson, 'map') rivers = geojson_handler(geojson, 'mapline') cities = geojson_handler(geojson, 'mappoint') specialCityLabels = {
# -*- coding: utf-8 -*- """ Highmaps Demos Drilldown: http://www.highcharts.com/maps/demo/map-drilldown """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler H = Highmap() H.add_CSSsource('http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') """ This example is to show how to generate drilldown map with both state and county level data in the US without using the JS functions as shown in Highmaps Demos The drilldown data can be added using add_drilldown_data_set method: add_drilldown_data_set(data, series_type, id, **kwargs) 1. data is the dataset for drilldown level 2. series_type is the type of plot presented at the drilldown level 3. id is the identifier used for the drilldown parent point to identify its series. This needs to be consistent with the drilldown property in dataset of parent level 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) However, the tradeoff is that user needs to query and handle the whole dataset in python environment and put the whole dataset into the .html file, which could make final file very big. """ map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url)
# -*- coding: utf-8 -*- """ Highmaps Demos Color axis and data labels: http://www.highcharts.com/maps/demo/color-axis """ from highcharts import Highmap H = Highmap(width = 650, height = 550) options = { 'chart' : { 'borderWidth' : 1 }, 'title' : { 'text' : 'US population density (/km²)' }, 'legend': { 'layout': 'horizontal', 'borderWidth': 0, 'backgroundColor': 'rgba(255,255,255,0.85)', 'floating': True, 'verticalAlign': 'top', 'y': 25 }, 'mapNavigation': { 'enabled': True },
# -*- coding: utf-8 -*- """ Highmaps Demos Detailed map, US counties: http://www.highcharts.com/maps/demo/us-counties """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import json_loader, js_map_loader, geojson_handler H = Highmap() """ This example generates the same map as us-counties.py, but using functions in highmap_helper module to handle data in python environment completely """ options = { 'chart': { 'borderWidth': 1, 'marginRight': 50 }, 'title': { 'text': 'US Counties unemployment rates, April 2015' }, 'legend': { 'title': { 'text': 'Unemployment<br>rate', 'style': { 'color': "(Highcharts.theme && Highcharts.theme.textColor) || 'black'" } },
data: data, dataLabels: { enabled: true, format: '{point.name}' } }); }); } this.setTitle(null, { text: e.point.name }); }""", } H = Highmap() """ Drilldown map requires an additional JS library from highcharts, which can be added using add_JSsource method Also, it needs a bootstrap CSS file, which is added using add_CSSsource method """ H.add_JSsource('http://code.highcharts.com/maps/modules/drilldown.js') H.add_CSSsource('http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown':item['properties']['hc-key']})
# -*- coding: utf-8 -*- """ Highmaps Demos Color axis and data labels: http://www.highcharts.com/maps/demo/color-axis """ from highcharts import Highmap H = Highmap(width=650, height=550) options = { 'chart': { 'borderWidth': 1 }, 'title': { 'text': 'US population density (/km²)' }, 'legend': { 'layout': 'horizontal', 'borderWidth': 0, 'backgroundColor': 'rgba(255,255,255,0.85)', 'floating': True, 'verticalAlign': 'top', 'y': 25 }, 'mapNavigation': { 'enabled': True }, 'colorAxis': { 'min': 1, 'type': 'logarithmic', 'minColor': '#EEEEFF',
# -*- coding: utf-8 -*- """ Highmaps Demos Advanced lat/long: http://www.highcharts.com/maps/demo/latlon-advanced """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler, interpolateRGB H = Highmap(height=550) map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-capitals.json&callback=?' geojson = js_map_loader(map_url) data = jsonp_loader(data_url) options = { 'title': { 'text': 'Highmaps lat/lon demo' }, 'tooltip': { 'formatter': "function () {\ return this.point.capital + ', ' + this.point.parentState + '<br>Lat: ' + this.point.lat + ' Lon: ' + this.point.lon + '<br>Population: ' + this.point.population;\ }", 'crosshairs': [{ 'zIndex': 5, 'dashStyle': 'dot', 'snap': False, 'color': 'gray' }, { 'zIndex': 5,
from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler, interpolateRGB H = Highmap(height=550) map_url = 'http://code.highcharts.com/mapdata/countries/cl/cl-all.js' data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-capitals.json&callback=?' geojson = js_map_loader(map_url) data = [ { u'lon': -86.300629, u'abbrev': u'AL', u'capital': u'Montgomery', u'lat': 32.38012, 'z': 205764, u'parentState': u'Alabama', u'population': 205764 }, { u'lon': -92.274494, u'abbrev': u'AR', u'capital': u'Little Rock', u'lat': 34.748655, 'z': 193524, u'parentState': u'Arkansas', u'population': 193524 }, ] # geographical data geo = { 'sym': {
# -*- coding: utf-8 -*- """ Highmaps Demos Drilldown: http://www.highcharts.com/maps/demo/map-drilldown """ from highcharts import Highmap from highcharts.highmaps.highmap_helper import jsonp_loader, js_map_loader, geojson_handler H = Highmap() H.add_CSSsource( 'http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') """ This example is to show how to generate drilldown map with both state and county level data in the US without using the JS functions as shown in Highmaps Demos The drilldown data can be added using add_drilldown_data_set method: add_drilldown_data_set(data, series_type, id, **kwargs) 1. data is the dataset for drilldown level 2. series_type is the type of plot presented at the drilldown level 3. id is the identifier used for the drilldown parent point to identify its series. This needs to be consistent with the drilldown property in dataset of parent level 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) However, the tradeoff is that user needs to query and handle the whole dataset in python environment and put the whole dataset into the .html file, which could make final file very big. """ map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url)