Exemplo n.º 1
0
# -*- coding: utf-8 -*-
"""
Highstock Demos
Two panes, candlestick and volume: http://www.highcharts.com/stock/demo/candlestick-and-volume
"""
from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader
H = Highstock()

data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?'
data = jsonp_loader(data_url, sub_d=r'(\/\*.*\*\/)')

ohlc = []
volume = []
groupingUnits = [['week', [1]], ['month', [1, 2, 3, 4, 6]]]

for i in range(len(data)):
    ohlc.append([
        data[i][0],  # the date
        data[i][1],  # open
        data[i][2],  # high
        data[i][3],  # low
        data[i][4]  # close
    ])
    volume.append([
        data[i][0],  # the date
        data[i][5]  # the volume 
    ])

options = {
    'rangeSelector': {
"""
This example generates the same chart as flags-general.py
But instead of copying from the website, the dataset is queried direcly using jsonp_loader
The json doc from the url is not in the correct format (lack of quotes), so the sub_d and sub_by parameters
are used to fix the problem.
"""

import datetime
from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader

H = Highstock()

data_url = "http://www.highcharts.com/samples/data/jsonp.php?filename=usdeur.json&callback=?"
data = jsonp_loader(
    data_url, sub_d=r"(Date\.UTC\(([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?\))", sub_by=r'"\1"'
)  # data from url is not in right json format

data2 = [
    {"x": datetime.datetime(2015, 6, 8), "title": "C", "text": "Stocks fall on Greece, rate concerns; US dollar dips"},
    {
        "x": datetime.datetime(2015, 6, 12),
        "title": "D",
        "text": "Zimbabwe ditches 'worthless' currency for the US dollar ",
    },
    {"x": datetime.datetime(2015, 6, 19), "title": "E", "text": "US Dollar Declines Over the Week on Rate Timeline"},
    {
        "x": datetime.datetime(2015, 6, 26),
        "title": "F",
        "text": "Greek Negotiations Take Sharp Turn for Worse, US Dollar set to Rally ",
    },
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
"""
Highstock Demos
Compare multiple series: http://www.highcharts.com/stock/demo/compare
"""

from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader

H = Highstock()

names = ["MSFT", "AAPL", "GOOG"]

for name in names:
    data_url = "http://www.highcharts.com/samples/data/jsonp.php?filename=" + name.lower() + "-c.json&callback=?"
    data = jsonp_loader(data_url, sub_d=r"(\/\*.*\*\/)")

    H.add_data_set(data, "line", name)


options = {
    "rangeSelector": {"selected": 4},
    "yAxis": {
        "labels": {
            "formatter": "function () {\
                            return (this.value > 0 ? ' + ' : '') + this.value + '%';\
                        }"
        },
        "plotLines": [{"value": 0, "width": 2, "color": "silver"}],
    },
    "plotOptions": {"series": {"compare": "percent"}},
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
"""
Highstock Demos
Single line series: http://www.highcharts.com/stock/demo/basic-line
"""
"""
This example generates the same highstocks chart as Example1-basic-line.py, 
but use jsonp_loader from highstock_helper instead of add_data_from_jsonp

jsonp_loader(url, prefix_regex=r'^(.*\()', suffix_regex=r'(\);)$', sub_d=None, sub_by='')
jsonp_loader is to request (JSON) data from a server in a different domain (JSONP) 
and covert to python readable data. 
    1. url is the url (https) where data is located
    2. "prefix_regex" and "suffix_regex" are regex patterns used to 
        remove JSONP specific prefix and suffix, such as callback header: "callback(" and end: ");", 
    3. "sub_d" is regex patterns for any unwanted string in loaded json data (will be replaced by sub_by). 
    4. "sub_by" is the string to replace any unwanted string defined by sub_d
For function coverstion, such as Data.UTC to datetime.datetime, please check JSONPDecoder
"""

from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader
H = Highstock()

data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?'
data = jsonp_loader(
    data_url,
    sub_d=r'(\/\*.*\*\/)')  # to remove the comment in json doc from the url

options = {
    'rangeSelector': {
Exemplo n.º 5
0
def hc_load_sample_data(name):
    """Loads Highcharts sample data from https://www.highcharts.com/samples/data/jsonp.php."""
    url = "https://www.highcharts.com/samples/data/jsonp.php?filename=%s.json&callback=?" % name
    return jsonp_loader(url)
# -*- coding: utf-8 -*-
"""
Highstock Demos
Single line series: http://www.highcharts.com/stock/demo/basic-line
"""

"""
This example generates the same highstocks chart as Example1-basic-line.py, 
but use jsonp_loader from highstock_helper instead of add_data_from_jsonp

jsonp_loader(url, prefix_regex=r'^(.*\()', suffix_regex=r'(\);)$', sub_d=None, sub_by='')
jsonp_loader is to request (JSON) data from a server in a different domain (JSONP) 
and covert to python readable data. 
    1. url is the url (https) where data is located
    2. "prefix_regex" and "suffix_regex" are regex patterns used to 
        remove JSONP specific prefix and suffix, such as callback header: "callback(" and end: ");", 
    3. "sub_d" is regex patterns for any unwanted string in loaded json data (will be replaced by sub_by). 
    4. "sub_by" is the string to replace any unwanted string defined by sub_d
For function coverstion, such as Data.UTC to datetime.datetime, please check JSONPDecoder
"""

from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader
H = Highstock()

data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?'
data = jsonp_loader(data_url, sub_d = r'(\/\*.*\*\/)') # to remove the comment in json doc from the url

options = {
    'rangeSelector' : {
            'selected' : 1
Exemplo n.º 7
0
def hc_load_sample_data(name):
    """Loads Highcharts sample data from https://www.highcharts.com/samples/data/jsonp.php."""
    url = "https://www.highcharts.com/samples/data/jsonp.php?filename=%s.json&callback=?" % name
    return jsonp_loader(url)
Exemplo n.º 8
0
"""
This example generates the same chart as flags-general.py
But instead of copying from the website, the dataset is queried direcly using jsonp_loader
The json doc from the url is not in the correct format (lack of quotes), so the sub_d and sub_by parameters
are used to fix the problem.
"""

import datetime
from highcharts import Highstock
from highcharts.highstock.highstock_helper import jsonp_loader
H = Highstock()

data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=usdeur.json&callback=?'
data = jsonp_loader(
    data_url,
    sub_d=
    r'(Date\.UTC\(([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?\))',
    sub_by=r'"\1"')  # data from url is not in right json format

data2 = [{
    'x': datetime.datetime(2015, 6, 8),
    'title': 'C',
    'text': 'Stocks fall on Greece, rate concerns; US dollar dips'
}, {
    'x': datetime.datetime(2015, 6, 12),
    'title': 'D',
    'text': 'Zimbabwe ditches \'worthless\' currency for the US dollar '
}, {
    'x': datetime.datetime(2015, 6, 19),
    'title': 'E',
    'text': 'US Dollar Declines Over the Week on Rate Timeline'