{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Asynchronous charts\n",
"\n",
"In this example we will take a look at asynchronous charts. Asynchronous charts offer some advantages over the normal synchronous charts:\n",
"\n",
"- The chart can hold any (!) amount of data\n",
"- You can draw a chart and add new data to the chart afterwards\n",
"\n",
"It does this by first making a separate JSON file of your series objects and stores them in a dedicated directory. When you select a variable from the variable-selector, the chart will load this data and display it! At any time you can add a series to the directory and notify the chart by pressing the `update` button.\n",
"\n",
"
\n",
"\n",
"Let's try this out. Import the library:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Server running in the folder /home/arnout/Projects/Work/python-highcharts at 127.0.0.1:47688\n"
]
}
],
"source": [
"import charts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice the line telling us their is a server running. This server is run in a separate thread and allows the use of asynchronous charts. You don't need to care so much just remember when you browse to the address listed there you can view your asynchronous charts (Charts will open a page at this address so you probably won't need it).\n",
"\n",
"
\n",
"\n",
"As in the previous example, lets load some data and default options. We set the title of the chart to `Asynchronous Chart`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"aapl = charts.data.aapl()\n",
"msft = charts.data.msft()\n",
"ohlc = charts.data.ohlc()\n",
"\n",
"series = [\n",
" aapl,\n",
" msft,\n",
" ohlc\n",
"]\n",
"options = dict()\n",
"options['title'] = dict(text='Asynchronous Chart')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### An inline chart\n",
"\n",
"We start by making an inline chart. As opposed to the syncronous charts, the `plotasync()` method returns a `Chart` object we will need to interact with the chart after it has been build. Create the chart and save it inside the `inline_chart` variable:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"inline_chart = charts.plotasync(\n",
" [aapl], options='testfile', stock=True, show='inline', save='stocks', display=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can notice two things:\n",
"\n",
"1. We included a new option `purge=True`\n",
"2. The chart is not displayed immediately \n",
"\n",
"An asyncronous chart saves the series data in separate json files inside a directory (given by the `save='stocks'` parameter) which can already exist. If set `purge=True` all the contents of the directory will be deleted. Go and check out the folder from which you executed this code and you will see a new folder called `stocks` where you chart data is stored.\n",
"\n",
"To display the chart, just call the `show()`method"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"