highcharts-excentis


Namehighcharts-excentis JSON
Version 0.4.5 PyPI version JSON
download
home_page
SummaryPython Highcharts wrapper
upload_time2024-02-02 13:28:30
maintainer
docs_urlNone
author
requires_python>=3.4
licenseCopyright (c) 2015 Kyper Data Technologies Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords python ipython highcharts chart visualization graph javascript html
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # highcharts-excentis

> This version is a fork of the original project by
> [Kyper Data](https://github.com/kyper-data/python-highcharts/).
>
> Unfortunately, the original maintainers no longer respond to issues,
> pull requests, e-mails or any other attempts to contact them.
>
> Therefor, we decided to fork their project and made some fixes for
> Python >= 3.10. A published version is also available at
> [PyPI](https://pypi.org/project/highcharts-excentis/)

## License

The python-highcharts wrapper is licensed under the [MIT license](http://opensource.org/licenses/MIT).

However, please be aware that the Highcharts project itself, as well as Highmaps and Highstock, are only free for non-commercial use under the Creative Commons Attribution-NonCommercial license. Commercial use requires the purchase of a separate license. Pop over to [Highcharts](http://shop.highsoft.com/) for more information.

## Overview

python-highcharts is a simple translation layer between Python and Javascript for Highcharts projects (highcharts, highmaps, and highstocks).

In addition, python-highcharts integrates with [Jupyter notebook](https://github.com/jupyter/notebook), which enables you to render Highcharts, Highmaps, and Highstock visualizations directly in notebooks. See examples [here](https://github.com/kyper-data/python-highcharts/tree/developer/examples/ipynb).

The original framework was inspired by [python-nvd3](https://github.com/areski/python-nvd3) and [PyHighcharts](https://github.com/fidyeates/PyHighcharts).

## Installation

python-highcharts supports Python 2.7/3.4+ and is available on
[PyPI](https://pypi.org/project/highcharts-excentis/). To install:
```
pip install highcharts-excentis
```

---------------------------------------------------------------------------------------------------------------
# Highcharts/Highstock

## Basic Usage

Usage of python-highcharts is very similar to usage of the original Javascript library. 

The main input is a python dictionary similar to Highcharts's 'options' object. The dictionary supports most options listed in the official [Highcharts documentation](http://api.highcharts.com/highcharts). 

However, the data_set(s) need to be input by a separate function.

```python
from highcharts_excentis import Highchart

# A chart is the container that your data will be rendered in, it can (obviously) support multiple data series within it.
chart = Highchart()

# Adding a series requires at minimum an array of data points. 
# You can also change the series type, the name, or other series options as kwargs.
data = range(1,20)
chart.add_data_set(data, series_type='line', name='Example Series')

# This will generate and save a .html file at the location you assign
chart.save_file()
```

You can add chart options using set_options. Ex:
```python
chart.set_options('chart', {'resetZoomButton': {'relativeTo': 'plot', 'position': {'x': 0,'y': -30}}})
chart.set_options('xAxis', {'events': {'afterBreaks': 'function(e){return}'}})
chart.set_options('tooltip', {'formatter': 'default_tooltip'})
```

The set_options function can update the options automatically if you input the same option_type. Ex:
```python
chart.set_options('chart', {'style': {"fontSize": '22px'}})
chart.set_options('chart', {'resetZoomButton': {'position': {'x': 10}}})
chart.set_options('chart', {'resetZoomButton': {'relativeTo': 'chart'}})
chart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 2, 'to': 4}})
chart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 6, 'to': 8}})
chart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 10, 'to': 12}})
```

However, the better practice is to construct chart options by a dictionary (as Highcharts suggests: http://www.highcharts.com/docs/getting-started/your-first-chart) and then input by the set_dict_options function. Ex:
```python
options = {
    'title': {
        'text': 'Atmosphere Temperature by Altitude'
    },
    'subtitle': {
        'text': 'According to the Standard Atmosphere Model'
    },
    'xAxis': {
        'reversed': False,
        'title': {
            'enabled': True,
            'text': 'Altitude'
        },
        'labels': {
            'formatter': 'function () {\
                return this.value + "km";\
            }'
        },
        'maxPadding': 0.05,
        'showLastLabel': True
    },
    'yAxis': {
        'title': {
            'text': 'Temperature'
        },
        'labels': {
            'formatter': "function () {\
                return this.value + '°';\
            }"
        },
        'lineWidth': 2
    },
    'legend': {
        'enabled': False
    },
    'tooltip': {
        'headerFormat': '<b>{series.name}</b><br/>',
        'pointFormat': '{point.x} km: {point.y}°C'
    }
}

chart.set_dict_options(options)
```

Unlike Javascript Highcharts, the series option can't be included in the options dictionary. It needs to input by the add_data_set (and/or add_drilldown_data_set) function, Ex:
```python
chart.add_data_set(data, 'scatter', 'Outlier', 
    marker={
        'fillColor': 'white',
        'lineWidth': 1,
        'lineColor': 'Highcharts.getOptions().colors[0]'
    },
    tooltip={'pointFormat': 'Observation: {point.y}'}
)

chart.add_drilldown_data_set(data_2, 'column', 'Chrome', name='Chrome')
```


## Example Usage

```python
from highcharts_excentis import Highchart
chart = Highchart()

chart.set_options('chart', {'inverted': True})

options = {
    'title': {
        'text': 'Atmosphere Temperature by Altitude'
    },
    'subtitle': {
        'text': 'According to the Standard Atmosphere Model'
    },
    'xAxis': {
        'reversed': False,
        'title': {
            'enabled': True,
            'text': 'Altitude'
        },
        'labels': {
            'formatter': 'function () {\
                return this.value + "km";\
            }'
        },
        'maxPadding': 0.05,
        'showLastLabel': True
    },
    'yAxis': {
        'title': {
            'text': 'Temperature'
        },
        'labels': {
            'formatter': "function () {\
                return this.value + '°';\
            }"
        },
        'lineWidth': 2
    },
    'legend': {
        'enabled': False
    },
    'tooltip': {
        'headerFormat': '<b>{series.name}</b><br/>',
        'pointFormat': '{point.x} km: {point.y}°C'
    }
}

chart.set_dict_options(options)
data =  [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], 
[50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
chart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) 

chart.save_file()

```

## Jupyter/IPython notebook

To render charts in Jupyter notebooks, simply put the chart object on the last line of a cell:

```python
chart.set_dict_options(options)
data =  [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], 
[50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
chart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) 

chart
```

### Example notebooks:

* [Highcharts](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highcharts/Example1.ipynb)
* [Highmaps](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highmaps/Example1.ipynb)
* [Highstock](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highstock/Example1-basic-line.ipynb)

## Todo:

* More charts support
* Clean code and put more explanation

Reference: [Highcharts API](http://api.highcharts.com/highcharts)

---------------------------------------------------------------------------------------------------------------
# Highmaps

## Basic Usage

Usage of python-highcharts is very similar to usage of the original Javascript library. 

The main input is a python dictionary similar to Highmaps's 'options' object. The dictionary supports most options listed in the official [Highmaps documentation](http://api.highcharts.com/highmaps). 

However, the data_set(s) need to be input by a separate function.

```python
from highcharts_excentis import Highmap

# A chart is the container that your data will be rendered in, it can (obviously) support multiple data series within it.
chart = Highmap()

# Adding a series requires a minimum of one argument, an array of data points
chart.add_data_set(data, series_type='map', name='Example Series')

# This will generate and save a .html file at the location you assign
chart.save_file()
```

Although you can add chart option using set_options, but
a better practice is to construct chart options by a dictionary (as highcharts suggests: http://www.highcharts.com/docs/getting-started/your-first-chart) and then input by set_dict_optoins function. Ex.

```python
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'"
            }
        },
        'layout': 'vertical',
        'align': 'right',
        'floating': True,
        'valueDecimals': 0,
        'valueSuffix': '%',
        'backgroundColor': "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'",
        'symbolRadius': 0,
        'symbolHeight': 14
    },

    'mapNavigation': {
        'enabled': True
    },

    'colorAxis': {
        'dataClasses': [{
            'from': 0,
            'to': 2,
            'color': "#F1EEF6"
        }, {
            'from': 2,
            'to': 4,
            'color': "#D4B9DA"
        }, {
            'from': 4,
            'to': 6,
            'color': "#C994C7"
        }, {
            'from': 6,
            'to': 8,
            'color': "#DF65B0"
        }, {
            'from': 8,
            'to': 10,
            'color': "#DD1C77"
        }, {
            'from': 10,
            'color': "#980043"
        }]
    },

    'plotOptions': {
        'map':{
        'mapData': 'geojson'

        },
        'mapline': {
            'showInLegend': False,
            'enableMouseTracking': False
        }
    },
} 

chart.set_dict_options(options)

```

The map data is set by set_map_source function. It is recommended to use the map collection on highcharts: http://code.highcharts.com/mapdata/

For the map properties visit: http://www.highcharts.com/docs/maps/map-collection

The default setting is to use the Highchart Javascript map.

```python

# set_map_source requires a least one argument: the map data url
chart.set_map_source('http://code.highcharts.com/mapdata/countries/us/us-all-all.js', jsonp_map = False)
```

However, the better practice is to load map data using function in highmap_helper library 
and convert it in preparation to be added directly by the add_map or add_data_set functions. 

```python
from highmap_helper import jsonp_loader, js_map_loader, geojson_handler

map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js'

# Load .js format map data from the source and convert to GeoJSON object
geojson = js_map_loader(map_url)

# Similarly, json format (jsonp) map data can be loaded using:
geojson = jsonp_loader("a_jsonp_map_url")

# Reconstruct a GeoJSON object in preparation to be read directly. 
# geojson_handler function is similar to Highcharts.geojson in Highcharts: http://api.highcharts.com/highmaps#Highcharts.geojson
mapdata = geojson_handler(geojson)

chart.add_map_data(mapdata)

```

The series option in Highmaps needs to be input separately using add_data_set (and/or add_drilldown_data_set) function, Ex.

```python
chart.add_data_set(data, 'map', 'Unemployment rate', joinBy=['hc-key', 'code'], 
    tooltip={
        'valueSuffix': '%'
    },
    borderWidth = 0.5,
    states={
        'hover': {
            'color': '#bada55'
        }
    }
)
chart.add_drilldown_data_set(sub_data, 'map', id=mapkey, name=item['name'], 
    dataLabels={
        'enabled': True,
        'format': '{point.name}'
    }
)
```

The data set can be loaded directly from the url (jsonp format), but it is not recommended:
```python
data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'
chart.add_data_from_jsonp(data_url, 'json_data', 'map', 'Unemployment rate', joinBy=['hc-key', 'code'], 
    tooltip={
        'valueSuffix': '%'
    },
    borderWidth = 0.5,
    states={
        'hover': {
            'color': '#bada55'
        }
    }
)

```

Furthermore, python-highcharts has a function to add Javascript in the beginning or the end of JQuery body: $(function(){},
but, again, it is not recommended unless it is really necessary. 

```python
# function requires at least two arguments: script (javascript) and location ('head' or 'end')
chart.add_JSscript("var lines = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline');", 'head')
```

## Examples

Bad practice: 
1) load data directly and handle it in Javascript 2) insert javascript into thea head 3) use unquote function RawJavaScriptText to prepare Javascript:
```python
from highcharts_excentis import Highmap
from common import RawJavaScriptText

chart = Highmap()

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'"
            }
        },
        'layout': 'vertical',
        'align': 'right',
        'floating': True,
        'valueDecimals': 0,
        'valueSuffix': '%',
        'backgroundColor': "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'",
        'symbolRadius': 0,
        'symbolHeight': 14
    },
    'mapNavigation': {
        'enabled': True
    },
    'colorAxis': {
        'dataClasses': [{
            'from': 0,
            'to': 2,
            'color': "#F1EEF6"
        }, {
            'from': 2,
            'to': 4,
            'color': "#D4B9DA"
        }, {
            'from': 4,
            'to': 6,
            'color': "#C994C7"
        }, {
            'from': 6,
            'to': 8,
            'color': "#DF65B0"
        }, {
            'from': 8,
            'to': 10,
            'color': "#DD1C77"
        }, {
            'from': 10,
            'color': "#980043"
        }]
    },
    'plotOptions': {
        'mapline': {
            'showInLegend': False,
            'enableMouseTracking': False
        }
    }
} 

chart.set_dict_options(options)
data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'
chart.add_data_from_jsonp(data_url, 'json_data', 'map', 'Unemployment rate', 
    joinBy=['hc-key', 'code'], 
    tooltip={'valueSuffix': '%'},
    borderWidth=0.5,
    states={'hover': {'color': '#bada55'}}
)
chart.add_data_set(RawJavaScriptText('[lines[0]]'), 'mapline', 'State borders', color = 'white')
chart.add_data_set(RawJavaScriptText('[lines[1]]'), 'mapline', 'Separator', color = 'gray')
chart.set_map_source('http://code.highcharts.com/mapdata/countries/us/us-all-all.js', jsonp_map = False)
chart.add_JSscript("var lines = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline');", 'head')
chart.add_JSscript("Highcharts.each(geojson, function (mapPoint) {\
    mapPoint.name = mapPoint.name + ', ' + mapPoint.properties['hc-key'].substr(3, 2);\
});", 'head')

chart.save_file()
```

Better practice: 
```python

from highcharts_excentis import Highmap
from highmap_helper import jsonp_loader, js_map_loader, geojson_handler

chart = Highmap()
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'"
            }
        },
        'layout': 'vertical',
        'align': 'right',
        'floating': True,
        'valueDecimals': 0,
        'valueSuffix': '%',
        'backgroundColor': "(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'",
        'symbolRadius': 0,
        'symbolHeight': 14
    },
    'mapNavigation': {
        'enabled': True
    },
    'colorAxis': {
        'dataClasses': [{
            'from': 0,
            'to': 2,
            'color': "#F1EEF6"
        }, {
            'from': 2,
            'to': 4,
            'color': "#D4B9DA"
        }, {
            'from': 4,
            'to': 6,
            'color': "#C994C7"
        }, {
            'from': 6,
            'to': 8,
            'color': "#DF65B0"
        }, {
            'from': 8,
            'to': 10,
            'color': "#DD1C77"
        }, {
            'from': 10,
            'color': "#980043"
        }]
    },
    'plotOptions': {
        'map':{
            'mapData': 'geojson'
        },
        'mapline': {
            'showInLegend': False,
            'enableMouseTracking': False
        }
    }
} 

chart.set_dict_options(options)

# read data and map directly from url
data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'
map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js'

data = jsonp_loader(data_url)
geojson = js_map_loader(map_url)
mapdata = geojson_handler(geojson)
lines = geojson_handler(geojson, 'mapline')
for x in mapdata:
    x.update({'name':x['name']+', '+x['properties']['hc-key'].split('-')[1].upper()})

#map(lambda x: x['properties'].update({'name':x['properties']['name']+', '+x['properties']['hc-key'].split('-')[1]}), geojson['features'])

chart.add_data_set(data, 'map', 'Unemployment rate', joinBy = ['hc-key', 'code'], 
    tooltip={'valueSuffix': '%'},
    borderWidth=0.5,
    states={
        'hover': {
            'color': '#bada55'
        }
    }
)
chart.add_data_set([lines[0]], 'mapline', 'State borders', color = 'white')
chart.add_data_set([lines[3]], 'mapline', 'Separator', color = 'gray')
chart.add_map_data(mapdata)

chart.save_file()

```

## Todo:

* More examples
* Clean code and put more explanation

Reference: [Highcharts API](http://api.highcharts.com/highcharts)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "highcharts-excentis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.4",
    "maintainer_email": "Excentis Development Team <support@excentis.com>, Tom Ghyselinck <tom.ghyselinck@excentis.com>",
    "keywords": "python,ipython,highcharts,chart,visualization,graph,javascript,html",
    "author": "",
    "author_email": "Kyper Developers <developers@kyperdata.com>",
    "download_url": "https://files.pythonhosted.org/packages/d3/6c/ae32f22db8588485305a4cded582c6ad112a47e7db264824281066e9f94e/highcharts-excentis-0.4.5.tar.gz",
    "platform": null,
    "description": "# highcharts-excentis\n\n> This version is a fork of the original project by\n> [Kyper Data](https://github.com/kyper-data/python-highcharts/).\n>\n> Unfortunately, the original maintainers no longer respond to issues,\n> pull requests, e-mails or any other attempts to contact them.\n>\n> Therefor, we decided to fork their project and made some fixes for\n> Python >= 3.10. A published version is also available at\n> [PyPI](https://pypi.org/project/highcharts-excentis/)\n\n## License\n\nThe python-highcharts wrapper is licensed under the [MIT license](http://opensource.org/licenses/MIT).\n\nHowever, please be aware that the Highcharts project itself, as well as Highmaps and Highstock, are only free for non-commercial use under the Creative Commons Attribution-NonCommercial license. Commercial use requires the purchase of a separate license. Pop over to [Highcharts](http://shop.highsoft.com/) for more information.\n\n## Overview\n\npython-highcharts is a simple translation layer between Python and Javascript for Highcharts projects (highcharts, highmaps, and highstocks).\n\nIn addition, python-highcharts integrates with [Jupyter notebook](https://github.com/jupyter/notebook), which enables you to render Highcharts, Highmaps, and Highstock visualizations directly in notebooks. See examples [here](https://github.com/kyper-data/python-highcharts/tree/developer/examples/ipynb).\n\nThe original framework was inspired by [python-nvd3](https://github.com/areski/python-nvd3) and [PyHighcharts](https://github.com/fidyeates/PyHighcharts).\n\n## Installation\n\npython-highcharts supports Python 2.7/3.4+ and is available on\n[PyPI](https://pypi.org/project/highcharts-excentis/). To install:\n```\npip install highcharts-excentis\n```\n\n---------------------------------------------------------------------------------------------------------------\n# Highcharts/Highstock\n\n## Basic Usage\n\nUsage of python-highcharts is very similar to usage of the original Javascript library. \n\nThe main input is a python dictionary similar to Highcharts's 'options' object. The dictionary supports most options listed in the official [Highcharts documentation](http://api.highcharts.com/highcharts). \n\nHowever, the data_set(s) need to be input by a separate function.\n\n```python\nfrom highcharts_excentis import Highchart\n\n# A chart is the container that your data will be rendered in, it can (obviously) support multiple data series within it.\nchart = Highchart()\n\n# Adding a series requires at minimum an array of data points. \n# You can also change the series type, the name, or other series options as kwargs.\ndata = range(1,20)\nchart.add_data_set(data, series_type='line', name='Example Series')\n\n# This will generate and save a .html file at the location you assign\nchart.save_file()\n```\n\nYou can add chart options using set_options. Ex:\n```python\nchart.set_options('chart', {'resetZoomButton': {'relativeTo': 'plot', 'position': {'x': 0,'y': -30}}})\nchart.set_options('xAxis', {'events': {'afterBreaks': 'function(e){return}'}})\nchart.set_options('tooltip', {'formatter': 'default_tooltip'})\n```\n\nThe set_options function can update the options automatically if you input the same option_type. Ex:\n```python\nchart.set_options('chart', {'style': {\"fontSize\": '22px'}})\nchart.set_options('chart', {'resetZoomButton': {'position': {'x': 10}}})\nchart.set_options('chart', {'resetZoomButton': {'relativeTo': 'chart'}})\nchart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 2, 'to': 4}})\nchart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 6, 'to': 8}})\nchart.set_options('xAxis', {'plotBands': {'color': '#FCFFC5', 'from': 10, 'to': 12}})\n```\n\nHowever, the better practice is to construct chart options by a dictionary (as Highcharts suggests: http://www.highcharts.com/docs/getting-started/your-first-chart) and then input by the set_dict_options function. Ex:\n```python\noptions = {\n    'title': {\n        'text': 'Atmosphere Temperature by Altitude'\n    },\n    'subtitle': {\n        'text': 'According to the Standard Atmosphere Model'\n    },\n    'xAxis': {\n        'reversed': False,\n        'title': {\n            'enabled': True,\n            'text': 'Altitude'\n        },\n        'labels': {\n            'formatter': 'function () {\\\n                return this.value + \"km\";\\\n            }'\n        },\n        'maxPadding': 0.05,\n        'showLastLabel': True\n    },\n    'yAxis': {\n        'title': {\n            'text': 'Temperature'\n        },\n        'labels': {\n            'formatter': \"function () {\\\n                return this.value + '\u00b0';\\\n            }\"\n        },\n        'lineWidth': 2\n    },\n    'legend': {\n        'enabled': False\n    },\n    'tooltip': {\n        'headerFormat': '<b>{series.name}</b><br/>',\n        'pointFormat': '{point.x} km: {point.y}\u00b0C'\n    }\n}\n\nchart.set_dict_options(options)\n```\n\nUnlike Javascript Highcharts, the series option can't be included in the options dictionary. It needs to input by the add_data_set (and/or add_drilldown_data_set) function, Ex:\n```python\nchart.add_data_set(data, 'scatter', 'Outlier', \n    marker={\n        'fillColor': 'white',\n        'lineWidth': 1,\n        'lineColor': 'Highcharts.getOptions().colors[0]'\n    },\n    tooltip={'pointFormat': 'Observation: {point.y}'}\n)\n\nchart.add_drilldown_data_set(data_2, 'column', 'Chrome', name='Chrome')\n```\n\n\n## Example Usage\n\n```python\nfrom highcharts_excentis import Highchart\nchart = Highchart()\n\nchart.set_options('chart', {'inverted': True})\n\noptions = {\n    'title': {\n        'text': 'Atmosphere Temperature by Altitude'\n    },\n    'subtitle': {\n        'text': 'According to the Standard Atmosphere Model'\n    },\n    'xAxis': {\n        'reversed': False,\n        'title': {\n            'enabled': True,\n            'text': 'Altitude'\n        },\n        'labels': {\n            'formatter': 'function () {\\\n                return this.value + \"km\";\\\n            }'\n        },\n        'maxPadding': 0.05,\n        'showLastLabel': True\n    },\n    'yAxis': {\n        'title': {\n            'text': 'Temperature'\n        },\n        'labels': {\n            'formatter': \"function () {\\\n                return this.value + '\u00b0';\\\n            }\"\n        },\n        'lineWidth': 2\n    },\n    'legend': {\n        'enabled': False\n    },\n    'tooltip': {\n        'headerFormat': '<b>{series.name}</b><br/>',\n        'pointFormat': '{point.x} km: {point.y}\u00b0C'\n    }\n}\n\nchart.set_dict_options(options)\ndata =  [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], \n[50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]\nchart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) \n\nchart.save_file()\n\n```\n\n## Jupyter/IPython notebook\n\nTo render charts in Jupyter notebooks, simply put the chart object on the last line of a cell:\n\n```python\nchart.set_dict_options(options)\ndata =  [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], \n[50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]\nchart.add_data_set(data, 'spline', 'Temperature', marker={'enabled': False}) \n\nchart\n```\n\n### Example notebooks:\n\n* [Highcharts](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highcharts/Example1.ipynb)\n* [Highmaps](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highmaps/Example1.ipynb)\n* [Highstock](http://nbviewer.ipython.org/github/kyper-data/python-highcharts/blob/master/examples/ipynb/highstock/Example1-basic-line.ipynb)\n\n## Todo:\n\n* More charts support\n* Clean code and put more explanation\n\nReference: [Highcharts API](http://api.highcharts.com/highcharts)\n\n---------------------------------------------------------------------------------------------------------------\n# Highmaps\n\n## Basic Usage\n\nUsage of python-highcharts is very similar to usage of the original Javascript library. \n\nThe main input is a python dictionary similar to Highmaps's 'options' object. The dictionary supports most options listed in the official [Highmaps documentation](http://api.highcharts.com/highmaps). \n\nHowever, the data_set(s) need to be input by a separate function.\n\n```python\nfrom highcharts_excentis import Highmap\n\n# A chart is the container that your data will be rendered in, it can (obviously) support multiple data series within it.\nchart = Highmap()\n\n# Adding a series requires a minimum of one argument, an array of data points\nchart.add_data_set(data, series_type='map', name='Example Series')\n\n# This will generate and save a .html file at the location you assign\nchart.save_file()\n```\n\nAlthough you can add chart option using set_options, but\na better practice is to construct chart options by a dictionary (as highcharts suggests: http://www.highcharts.com/docs/getting-started/your-first-chart) and then input by set_dict_optoins function. Ex.\n\n```python\noptions = {\n    'chart': {\n        'borderWidth': 1,\n        'marginRight': 50 \n    },\n\n    'title': {\n        'text': 'US Counties unemployment rates, April 2015'\n    },\n\n    'legend': {\n        'title': {\n            'text': 'Unemployment<br>rate',\n            'style': {\n                'color': \"(Highcharts.theme && Highcharts.theme.textColor) || 'black'\"\n            }\n        },\n        'layout': 'vertical',\n        'align': 'right',\n        'floating': True,\n        'valueDecimals': 0,\n        'valueSuffix': '%',\n        'backgroundColor': \"(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'\",\n        'symbolRadius': 0,\n        'symbolHeight': 14\n    },\n\n    'mapNavigation': {\n        'enabled': True\n    },\n\n    'colorAxis': {\n        'dataClasses': [{\n            'from': 0,\n            'to': 2,\n            'color': \"#F1EEF6\"\n        }, {\n            'from': 2,\n            'to': 4,\n            'color': \"#D4B9DA\"\n        }, {\n            'from': 4,\n            'to': 6,\n            'color': \"#C994C7\"\n        }, {\n            'from': 6,\n            'to': 8,\n            'color': \"#DF65B0\"\n        }, {\n            'from': 8,\n            'to': 10,\n            'color': \"#DD1C77\"\n        }, {\n            'from': 10,\n            'color': \"#980043\"\n        }]\n    },\n\n    'plotOptions': {\n        'map':{\n        'mapData': 'geojson'\n\n        },\n        'mapline': {\n            'showInLegend': False,\n            'enableMouseTracking': False\n        }\n    },\n} \n\nchart.set_dict_options(options)\n\n```\n\nThe map data is set by set_map_source function. It is recommended to use the map collection on highcharts: http://code.highcharts.com/mapdata/\n\nFor the map properties visit: http://www.highcharts.com/docs/maps/map-collection\n\nThe default setting is to use the Highchart Javascript map.\n\n```python\n\n# set_map_source requires a least one argument: the map data url\nchart.set_map_source('http://code.highcharts.com/mapdata/countries/us/us-all-all.js', jsonp_map = False)\n```\n\nHowever, the better practice is to load map data using function in highmap_helper library \nand convert it in preparation to be added directly by the add_map or add_data_set functions. \n\n```python\nfrom highmap_helper import jsonp_loader, js_map_loader, geojson_handler\n\nmap_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js'\n\n# Load .js format map data from the source and convert to GeoJSON object\ngeojson = js_map_loader(map_url)\n\n# Similarly, json format (jsonp) map data can be loaded using:\ngeojson = jsonp_loader(\"a_jsonp_map_url\")\n\n# Reconstruct a GeoJSON object in preparation to be read directly. \n# geojson_handler function is similar to Highcharts.geojson in Highcharts: http://api.highcharts.com/highmaps#Highcharts.geojson\nmapdata = geojson_handler(geojson)\n\nchart.add_map_data(mapdata)\n\n```\n\nThe series option in Highmaps needs to be input separately using add_data_set (and/or add_drilldown_data_set) function, Ex.\n\n```python\nchart.add_data_set(data, 'map', 'Unemployment rate', joinBy=['hc-key', 'code'], \n    tooltip={\n        'valueSuffix': '%'\n    },\n    borderWidth = 0.5,\n    states={\n        'hover': {\n            'color': '#bada55'\n        }\n    }\n)\nchart.add_drilldown_data_set(sub_data, 'map', id=mapkey, name=item['name'], \n    dataLabels={\n        'enabled': True,\n        'format': '{point.name}'\n    }\n)\n```\n\nThe data set can be loaded directly from the url (jsonp format), but it is not recommended:\n```python\ndata_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'\nchart.add_data_from_jsonp(data_url, 'json_data', 'map', 'Unemployment rate', joinBy=['hc-key', 'code'], \n    tooltip={\n        'valueSuffix': '%'\n    },\n    borderWidth = 0.5,\n    states={\n        'hover': {\n            'color': '#bada55'\n        }\n    }\n)\n\n```\n\nFurthermore, python-highcharts has a function to add Javascript in the beginning or the end of JQuery body: $(function(){},\nbut, again, it is not recommended unless it is really necessary. \n\n```python\n# function requires at least two arguments: script (javascript) and location ('head' or 'end')\nchart.add_JSscript(\"var lines = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline');\", 'head')\n```\n\n## Examples\n\nBad practice: \n1) load data directly and handle it in Javascript 2) insert javascript into thea head 3) use unquote function RawJavaScriptText to prepare Javascript:\n```python\nfrom highcharts_excentis import Highmap\nfrom common import RawJavaScriptText\n\nchart = Highmap()\n\noptions = {\n    'chart': {\n        'borderWidth': 1,\n        'marginRight': 50 \n    },\n    'title': {\n        'text': 'US Counties unemployment rates, April 2015'\n    },\n    'legend': {\n        'title': {\n            'text': 'Unemployment<br>rate',\n            'style': {\n                'color': \"(Highcharts.theme && Highcharts.theme.textColor) || 'black'\"\n            }\n        },\n        'layout': 'vertical',\n        'align': 'right',\n        'floating': True,\n        'valueDecimals': 0,\n        'valueSuffix': '%',\n        'backgroundColor': \"(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'\",\n        'symbolRadius': 0,\n        'symbolHeight': 14\n    },\n    'mapNavigation': {\n        'enabled': True\n    },\n    'colorAxis': {\n        'dataClasses': [{\n            'from': 0,\n            'to': 2,\n            'color': \"#F1EEF6\"\n        }, {\n            'from': 2,\n            'to': 4,\n            'color': \"#D4B9DA\"\n        }, {\n            'from': 4,\n            'to': 6,\n            'color': \"#C994C7\"\n        }, {\n            'from': 6,\n            'to': 8,\n            'color': \"#DF65B0\"\n        }, {\n            'from': 8,\n            'to': 10,\n            'color': \"#DD1C77\"\n        }, {\n            'from': 10,\n            'color': \"#980043\"\n        }]\n    },\n    'plotOptions': {\n        'mapline': {\n            'showInLegend': False,\n            'enableMouseTracking': False\n        }\n    }\n} \n\nchart.set_dict_options(options)\ndata_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'\nchart.add_data_from_jsonp(data_url, 'json_data', 'map', 'Unemployment rate', \n    joinBy=['hc-key', 'code'], \n    tooltip={'valueSuffix': '%'},\n    borderWidth=0.5,\n    states={'hover': {'color': '#bada55'}}\n)\nchart.add_data_set(RawJavaScriptText('[lines[0]]'), 'mapline', 'State borders', color = 'white')\nchart.add_data_set(RawJavaScriptText('[lines[1]]'), 'mapline', 'Separator', color = 'gray')\nchart.set_map_source('http://code.highcharts.com/mapdata/countries/us/us-all-all.js', jsonp_map = False)\nchart.add_JSscript(\"var lines = Highcharts.geojson(Highcharts.maps['countries/us/us-all-all'], 'mapline');\", 'head')\nchart.add_JSscript(\"Highcharts.each(geojson, function (mapPoint) {\\\n    mapPoint.name = mapPoint.name + ', ' + mapPoint.properties['hc-key'].substr(3, 2);\\\n});\", 'head')\n\nchart.save_file()\n```\n\nBetter practice: \n```python\n\nfrom highcharts_excentis import Highmap\nfrom highmap_helper import jsonp_loader, js_map_loader, geojson_handler\n\nchart = Highmap()\noptions = {\n    'chart': {\n        'borderWidth': 1,\n        'marginRight': 50 \n    },\n    'title': {\n        'text': 'US Counties unemployment rates, April 2015'\n    },\n    'legend': {\n        'title': {\n            'text': 'Unemployment<br>rate',\n            'style': {\n                'color': \"(Highcharts.theme && Highcharts.theme.textColor) || 'black'\"\n            }\n        },\n        'layout': 'vertical',\n        'align': 'right',\n        'floating': True,\n        'valueDecimals': 0,\n        'valueSuffix': '%',\n        'backgroundColor': \"(Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255, 255, 255, 0.85)'\",\n        'symbolRadius': 0,\n        'symbolHeight': 14\n    },\n    'mapNavigation': {\n        'enabled': True\n    },\n    'colorAxis': {\n        'dataClasses': [{\n            'from': 0,\n            'to': 2,\n            'color': \"#F1EEF6\"\n        }, {\n            'from': 2,\n            'to': 4,\n            'color': \"#D4B9DA\"\n        }, {\n            'from': 4,\n            'to': 6,\n            'color': \"#C994C7\"\n        }, {\n            'from': 6,\n            'to': 8,\n            'color': \"#DF65B0\"\n        }, {\n            'from': 8,\n            'to': 10,\n            'color': \"#DD1C77\"\n        }, {\n            'from': 10,\n            'color': \"#980043\"\n        }]\n    },\n    'plotOptions': {\n        'map':{\n            'mapData': 'geojson'\n        },\n        'mapline': {\n            'showInLegend': False,\n            'enableMouseTracking': False\n        }\n    }\n} \n\nchart.set_dict_options(options)\n\n# read data and map directly from url\ndata_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?'\nmap_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js'\n\ndata = jsonp_loader(data_url)\ngeojson = js_map_loader(map_url)\nmapdata = geojson_handler(geojson)\nlines = geojson_handler(geojson, 'mapline')\nfor x in mapdata:\n    x.update({'name':x['name']+', '+x['properties']['hc-key'].split('-')[1].upper()})\n\n#map(lambda x: x['properties'].update({'name':x['properties']['name']+', '+x['properties']['hc-key'].split('-')[1]}), geojson['features'])\n\nchart.add_data_set(data, 'map', 'Unemployment rate', joinBy = ['hc-key', 'code'], \n    tooltip={'valueSuffix': '%'},\n    borderWidth=0.5,\n    states={\n        'hover': {\n            'color': '#bada55'\n        }\n    }\n)\nchart.add_data_set([lines[0]], 'mapline', 'State borders', color = 'white')\nchart.add_data_set([lines[3]], 'mapline', 'Separator', color = 'gray')\nchart.add_map_data(mapdata)\n\nchart.save_file()\n\n```\n\n## Todo:\n\n* More examples\n* Clean code and put more explanation\n\nReference: [Highcharts API](http://api.highcharts.com/highcharts)\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2015 Kyper Data Technologies  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python Highcharts wrapper",
    "version": "0.4.5",
    "project_urls": {
        "Homepage": "https://github.com/excentis/python-highcharts"
    },
    "split_keywords": [
        "python",
        "ipython",
        "highcharts",
        "chart",
        "visualization",
        "graph",
        "javascript",
        "html"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b3798539ea594dff28e176546a82e8cc1b7d72edb573f39dec41fe2a77b84c3",
                "md5": "ad588c627756154409628b9fbaa97f2d",
                "sha256": "64b60b736fda408dccf2abf4c6fb4ac630f19d1a542cc01bf29612ca001a3442"
            },
            "downloads": -1,
            "filename": "highcharts_excentis-0.4.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad588c627756154409628b9fbaa97f2d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.4",
            "size": 66348,
            "upload_time": "2024-02-02T13:28:28",
            "upload_time_iso_8601": "2024-02-02T13:28:28.509193Z",
            "url": "https://files.pythonhosted.org/packages/8b/37/98539ea594dff28e176546a82e8cc1b7d72edb573f39dec41fe2a77b84c3/highcharts_excentis-0.4.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d36cae32f22db8588485305a4cded582c6ad112a47e7db264824281066e9f94e",
                "md5": "b1d15a510896b617f82dab13df68e9db",
                "sha256": "14533e2dc3577e76b2bf7e24e66dcc3be6070f976eefa2a33dc792eaf1a46701"
            },
            "downloads": -1,
            "filename": "highcharts-excentis-0.4.5.tar.gz",
            "has_sig": false,
            "md5_digest": "b1d15a510896b617f82dab13df68e9db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4",
            "size": 58471,
            "upload_time": "2024-02-02T13:28:30",
            "upload_time_iso_8601": "2024-02-02T13:28:30.677669Z",
            "url": "https://files.pythonhosted.org/packages/d3/6c/ae32f22db8588485305a4cded582c6ad112a47e7db264824281066e9f94e/highcharts-excentis-0.4.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-02 13:28:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "excentis",
    "github_project": "python-highcharts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "highcharts-excentis"
}
        
Elapsed time: 0.31205s