{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Basic example for highmaps module in python-highcharts\n",
"========================================================\n",
"\n",
"As in highcharts, datasets need to input using \"add_data_set\" method.\n",
"Options can be either set by the \"set_options\" method as shown here or\n",
"by constructing a option dictionary object and input using \"set_dict_options\" method (recommended)\n",
"\n",
"In highmaps, the map data can be input in multiple ways:\n",
"\n",
"1. add_map_data method: (recommended)\n",
" add_map_data(geojson, **kwargs)\n",
" set map directly to the input (geojson) data \n",
" geojson is the map data in geojson format\n",
"\n",
"2. set_map_source method:\n",
" set_map_source(map_src, jsonp_map = False)\n",
" map_src is the url (https) where map data is located,\n",
" it is recommended to get map data from highcharts' map collection: \n",
" https://code.highcharts.com/mapdata/\n",
" jsonp_map is boolean parameter if mapdata is loaded from jsonp\n",
" geojson (from jsonp) or .js are accepted formats. \n",
" default is javascript (.js) format (from highcharts)\n",
"\n",
"The following example is from Highmaps Demos\n",
"GeoJSON areas: http://www.highcharts.com/maps/demo/geojson"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from highcharts import Highmap\n",
"H = Highmap(width = 650, height = 500)\n",
"\n",
"options = { # construct option dict\n",
" \n",
" 'chart' :{ 'renderTo' : 'container'\n",
" },\n",
" \n",
" 'title' : {\n",
" 'text' : 'GeoJSON in Highmaps'\n",
" },\n",
"\n",
" 'mapNavigation': {\n",
" 'enabled': True,\n",
" 'buttonOptions': {\n",
" 'verticalAlign': 'bottom'\n",
" }\n",
" },\n",
"\n",
" 'colorAxis': {\n",
" },\n",
"} \n",
"\n",
"data = [ # input dataset \n",
" {\n",
" \"code\": \"DE.SH\",\n",
" \"value\": 728\n",
" },\n",
" {\n",
" \"code\": \"DE.BE\",\n",
" \"value\": 710\n",
" },\n",
" {\n",
" \"code\": \"DE.MV\",\n",
" \"value\": 963\n",
" },\n",
" {\n",
" \"code\": \"DE.HB\",\n",
" \"value\": 541\n",
" },\n",
" {\n",
" \"code\": \"DE.HH\",\n",
" \"value\": 622\n",
" },\n",
" {\n",
" \"code\": \"DE.RP\",\n",
" \"value\": 866\n",
" },\n",
" {\n",
" \"code\": \"DE.SL\",\n",
" \"value\": 398\n",
" },\n",
" {\n",
" \"code\": \"DE.BY\",\n",
" \"value\": 785\n",
" },\n",
" {\n",
" \"code\": \"DE.SN\",\n",
" \"value\": 223\n",
" },\n",
" {\n",
" \"code\": \"DE.ST\",\n",
" \"value\": 605\n",
" },\n",
" {\n",
" \"code\": \"DE.\",\n",
" \"value\": 361\n",
" },\n",
" {\n",
" \"code\": \"DE.NW\",\n",
" \"value\": 237\n",
" },\n",
" {\n",
" \"code\": \"DE.BW\",\n",
" \"value\": 157\n",
" },\n",
" {\n",
" \"code\": \"DE.HE\",\n",
" \"value\": 134\n",
" },\n",
" {\n",
" \"code\": \"DE.NI\",\n",
" \"value\": 136\n",
" },\n",
" {\n",
" \"code\": \"DE.TH\",\n",
" \"value\": 704\n",
" }\n",
"]\n",
"H.set_dict_options(options) # set options\n",
"H.add_data_set(data, 'map', 'Random data', joinBy=['code_hasc', 'code'], # set dataset\n",
" states={\n",
" 'hover': {\n",
" 'color': '#BADA55'\n",
" }\n",
" },\n",
" dataLabels={\n",
" 'enabled': True,\n",
" 'format': '{point.properties.postal}'\n",
" })\n",
"\n",
"H.set_map_source('http://www.highcharts.com/samples/data/jsonp.php?filename=germany.geo.json&callback=?', True) # set map data from the src (jsonp)\n",
"\n",
"H"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}