{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Highstock Demos\n", "================\n", "Flags marking events: http://www.highcharts.com/stock/demo/flags-general\n", "--------------------------------------------------------------------\n", "\n", "This example generates the same chart as flags-general.py\n", "But instead of copying from the website, the dataset is queried direcly using jsonp_loader\n", "The json doc from the url is not in the correct format (lack of quotes), so the sub_d and sub_by parameters\n", "are used to fix the problem." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import datetime\n", "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=usdeur.json&callback=?'\n", "data = jsonp_loader(data_url, \n", " sub_d = r'(Date\\.UTC\\(([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?\\))', \n", " sub_by = r'\"\\1\"') # data from url is not in right json format\n", "\n", "data2 = [{\n", " 'x' : datetime.datetime(2015, 6, 8),\n", " 'title' : 'C',\n", " 'text' : 'Stocks fall on Greece, rate concerns; US dollar dips'\n", " }, {\n", " 'x' : datetime.datetime(2015, 6, 12),\n", " 'title' : 'D',\n", " 'text' : 'Zimbabwe ditches \\'worthless\\' currency for the US dollar '\n", " }, {\n", " 'x' : datetime.datetime(2015, 6, 19),\n", " 'title' : 'E',\n", " 'text' : 'US Dollar Declines Over the Week on Rate Timeline'\n", " }, {\n", " 'x' : datetime.datetime(2015, 6, 26),\n", " 'title' : 'F',\n", " 'text' : 'Greek Negotiations Take Sharp Turn for Worse, US Dollar set to Rally '\n", " }, {\n", " 'x' : datetime.datetime(2015, 6, 29),\n", " 'title' : 'G',\n", " 'text' : 'Euro records stunning reversal against dollar'\n", " }, {\n", " 'x' : datetime.datetime(2015, 6, 30),\n", " 'title' : 'H',\n", " 'text' : 'Surging US dollar curbs global IT spend'\n", " }]\n", "\n", "H.add_data_set(data, 'line', 'USD to EUR', id = 'dataseries')\n", "H.add_data_set(data2, 'flags', onSeries = 'dataseries',\n", " shape = 'circlepin',\n", " width = 16)\n", "\n", "options = {\n", " 'rangeSelector' : {\n", " 'selected' : 0\n", " },\n", "\n", " 'title' : {\n", " 'text' : 'USD to EUR exchange rate'\n", " },\n", " 'tooltip': {\n", " 'style': {\n", " 'width': '200px'\n", " },\n", " 'valueDecimals': 4,\n", " 'shared' : True\n", " },\n", "\n", " 'yAxis' : {\n", " 'title' : {\n", " 'text' : 'Exchange rate'\n", " }\n", " },\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 }