Skip to content

Instantly share code, notes, and snippets.

@ppope
Created November 21, 2014 21:16
Show Gist options
  • Save ppope/c040f2306c69f8f5fc06 to your computer and use it in GitHub Desktop.
Save ppope/c040f2306c69f8f5fc06 to your computer and use it in GitHub Desktop.
Highstocks with brythonmagic
{
"metadata": {
"name": "",
"signature": "sha256:ffc1076e469d1f185a7898713f686a88b18f798d06a3c45ad163abee4f1a1d2b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"%load_ext brythonmagic"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Load Brython library"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%html\n",
"<script type=\"text/javascript\" src=\"http://www.brython.info/src/brython_dist.js\"></script>"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<script type=\"text/javascript\" src=\"http://www.brython.info/src/brython_dist.js\"></script>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x7f3ec85c25f8>"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Load Highstock library"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%HTML\n",
"<script type=\"text/javascript\" src=\"http://code.highcharts.com/stock/highstock.js\"></script>"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<script type=\"text/javascript\" src=\"http://code.highcharts.com/stock/highstock.js\"></script>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x7f3ec85c2a90>"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Attempt at making StockChart"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"html = \"\"\"<div id=\"hc_test\" style=\"width: 700px; height: 300px;\"></div>\"\"\""
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%brython -h html\n",
"from javascript import JSConstructor\n",
"from browser import window\n",
"from datetime import datetime\n",
"\n",
"Highcharts = window.Highcharts\n",
"\n",
"#This doesn't work.\n",
"#hc = JSConstructor(Highcharts.StockChart)\n",
"hc = JSConstructor(Highcharts.Chart)\n",
"\n",
"config = {\n",
" 'chart': {\n",
" 'renderTo': 'hc_test'\n",
" },\n",
" 'rangeSelector': {\n",
" 'selected' : 1\n",
" },\n",
" 'title' : {\n",
" 'text': 'USD to EUR exchange rate'\n",
" },\n",
" 'tooltip': {\n",
" 'style': {\n",
" 'width': '200px'\n",
" },\n",
" 'valueDecimals': 4\n",
" },\n",
"\n",
" 'yAxis': {\n",
" 'title': {\n",
" 'text': 'Exchange rate'\n",
" }\n",
" },\n",
" 'series': [{\n",
" 'name' : 'USD to EUR',\n",
" 'data' : [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],\n",
" 'id' : 'dataseries'\n",
"\n",
" # the event marker flags\n",
" }, {\n",
" type : 'flags',\n",
" 'data' : [{\n",
" 'x' : 1,\n",
" 'title' : 'H',\n",
" 'text' : 'Euro Contained by Channel Resistance'\n",
" }, {\n",
" 'x' : 2,\n",
" 'title' : 'G',\n",
" 'text' : 'EURUSD: Bulls Clear Path to 1.50 Figure'\n",
" }, {\n",
" 'x' : 3,\n",
" 'title' : 'F',\n",
" 'text' : 'EURUSD: Rate Decision to End Standstill'\n",
" }, {\n",
" 'x' : 4,\n",
" 'title' : 'E',\n",
" 'text' : 'EURUSD: Enter Short on Channel Break'\n",
" }, {\n",
" 'x' : 5,\n",
" 'title' : 'D',\n",
" 'text' : 'Forex: U.S. Non-Farm Payrolls Expand 244K, U.S. Dollar Rally Cut Short By Risk Appetite'\n",
" }, {\n",
" 'x' : 6,\n",
" 'title' : 'C',\n",
" 'text' : 'US Dollar: Is This the Long-Awaited Recovery or a Temporary Bounce?'\n",
" }],\n",
" 'onSeries' : 'dataseries',\n",
" 'shape' : 'circlepin',\n",
" 'width' : 16\n",
" }]\n",
" }\n",
"\n",
"\n",
"hc(config)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
" <script id=\"181920\" type=\"text/python\">\n",
"from javascript import JSConstructor\n",
"from browser import window\n",
"from datetime import datetime\n",
"\n",
"Highcharts = window.Highcharts\n",
"\n",
"#hc = JSConstructor(Highcharts.StockChart)\n",
"hc = JSConstructor(Highcharts.Chart)\n",
"\n",
"config = {\n",
" 'chart': {\n",
" 'renderTo': 'hc_test'\n",
" },\n",
" 'rangeSelector': {\n",
" 'selected' : 1\n",
" },\n",
" 'title' : {\n",
" 'text': 'USD to EUR exchange rate'\n",
" },\n",
" 'tooltip': {\n",
" 'style': {\n",
" 'width': '200px'\n",
" },\n",
" 'valueDecimals': 4\n",
" },\n",
"\n",
" 'yAxis': {\n",
" 'title': {\n",
" 'text': 'Exchange rate'\n",
" }\n",
" },\n",
" 'series': [{\n",
" 'name' : 'USD to EUR',\n",
" 'data' : [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6],\n",
" 'id' : 'dataseries'\n",
"\n",
" # the event marker flags\n",
" }, {\n",
" type : 'flags',\n",
" 'data' : [{\n",
" 'x' : 1,\n",
" 'title' : 'H',\n",
" 'text' : 'Euro Contained by Channel Resistance'\n",
" }, {\n",
" 'x' : 2,\n",
" 'title' : 'G',\n",
" 'text' : 'EURUSD: Bulls Clear Path to 1.50 Figure'\n",
" }, {\n",
" 'x' : 3,\n",
" 'title' : 'F',\n",
" 'text' : 'EURUSD: Rate Decision to End Standstill'\n",
" }, {\n",
" 'x' : 4,\n",
" 'title' : 'E',\n",
" 'text' : 'EURUSD: Enter Short on Channel Break'\n",
" }, {\n",
" 'x' : 5,\n",
" 'title' : 'D',\n",
" 'text' : 'Forex: U.S. Non-Farm Payrolls Expand 244K, U.S. Dollar Rally Cut Short By Risk Appetite'\n",
" }, {\n",
" 'x' : 6,\n",
" 'title' : 'C',\n",
" 'text' : 'US Dollar: Is This the Long-Awaited Recovery or a Temporary Bounce?'\n",
" }],\n",
" 'onSeries' : 'dataseries',\n",
" 'shape' : 'circlepin',\n",
" 'width' : 16\n",
" }]\n",
" }\n",
"\n",
"\n",
"hc(config)\n",
" </script>\n",
" <div id=\"brython_container_181920\"><div id=\"hc_test\" style=\"width: 700px; height: 300px;\"></div></div>\n",
" <script type=\"text/javascript\">brython({debug:1, static_stdlib_import: false, ipy_id: [\"181920\"]});</script>\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x7f3ec8136208>"
]
}
],
"prompt_number": 28
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment