{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Highstock Demos\n",
"=========\n",
"Single line series: http://www.highcharts.com/stock/demo/basic-line\n",
"-----------------------------------------------------------------\n",
"\n",
"This example generates the same highstocks chart as Example1-basic-line.py, \n",
"but use jsonp_loader from highstock_helper instead of add_data_from_jsonp\n",
"\n",
"jsonp_loader(url, prefix_regex=r'^(.*\\()', suffix_regex=r'(\\);)$', sub_d=None, sub_by='')\n",
"jsonp_loader is to request (JSON) data from a server in a different domain (JSONP) \n",
"and convert to python readable data. \n",
" 1. url is the url (https) where data is located\n",
" 2. \"prefix_regex\" and \"suffix_regex\" are regex patterns used to \n",
" remove JSONP specific prefix and suffix, such as callback header: \"callback(\" and end: \");\", \n",
" 3. \"sub_d\" is regex patterns for any unwanted string in loaded json data (will be replaced by sub_by). \n",
" 4. \"sub_by\" is the string to replace any unwanted string defined by sub_d\n",
"For function coversion, such as Data.UTC to datetime.datetime, please check JSONPDecoder."
]
},
{
"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 Highstock\n",
"from highcharts.highstock.highstock_helper import jsonp_loader\n",
"H = Highstock()\n",
"\n",
"data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?'\n",
"data = jsonp_loader(data_url, sub_d = r'(\\/\\*.*\\*\\/)') # to remove the comment in json doc from the url\n",
"\n",
"options = {\n",
" 'rangeSelector' : {\n",
" 'selected' : 1\n",
" },\n",
"\n",
" 'title' : {\n",
" 'text' : 'AAPL Stock Price'\n",
" },\n",
"}\n",
"\n",
"H.add_data_set(data, 'line', 'AAPL', tooltip = {\n",
" 'valueDecimals': 2\n",
" }\n",
")\n",
"\n",
"H.set_dict_options(options)\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
}