def plot(self, title=False, width=600, height=300, load_js=None, js_sources=[]): chart_height = (height + 50) * self.number_of_candlestick_charts - 50 + 200 H = Highstock(width=width, height=chart_height) groupingUnits = [ ['hour', [60]], ] with open( os.path.join(os.path.dirname(os.path.abspath(__file__)), "files/load.jinja")) as f: load_tempate = jinja2.Template(f.read()) options = { 'rangeSelector': { 'buttons': [{ 'type': 'minute', 'count': 180, 'text': '3h' }, { 'type': 'minute', 'count': 360, 'text': '6h' }, { 'type': 'minute', 'count': 720, 'text': '12h' }, { 'type': 'minute', 'count': 60 * 24, 'text': '1d' }, { 'type': 'minute', 'count': 60 * 48, 'text': '2d' }, { 'type': 'second', 'count': 1, 'text': '1s' }, { 'type': 'second', 'count': 10, 'text': '10s' }], 'selected': 4, 'inputEnabled': False }, 'plotOptions': { 'series': { 'turboThreshold:': 0, 'dataGrouping': { 'enabled': False, }, 'animation': False, }, 'scatter': { 'turboThreshold:': 0, 'marker': { 'radius': 5, 'symbol': 'circle', 'states': { 'hover': { 'enabled': True, 'lineColor': 'rgb(100,100,100)' } } }, 'tooltip': { 'pointFormat': '{series.name} x:{point.x}, y:{point.y}' #'pointFormatter': """ #function () { debugger; } #""" }, 'states': { 'hover': { 'marker': { 'enabled': False } } }, }, }, 'navigator': { 'enabled': True, 'height': 20 }, 'chart': { 'animation': False, }, 'title': { 'text': '', 'style': { 'display': 'none' } }, 'legend': { 'enabled': True, }, 'yAxis': [] } if title: options['title'] = {'text': title} if load_js: load_js = load_tempate.render(symbols=self.symbols) options['event']['load'] = load_js idx = -1 current_y = -height for chart_type, symbol, data, is_new_chart in self.symbols: if is_new_chart: idx += 1 current_y += height + 50 options['yAxis'].append({ 'labels': { 'align': 'right', 'x': -3 }, 'title': { 'text': 'y' }, 'top': '%dpx' % (current_y), 'height': '%dpx' % (height), 'lineWidth': 2, 'offset': 0, }) if chart_type == 'candlestick': H.add_data_set(data, chart_type, symbol, yAxis=idx, dataGrouping={}) elif chart_type == 'line': H.add_data_set(data, chart_type, symbol, yAxis=idx, dataGrouping={}) elif chart_type == 'scatter': H.add_data_set(data, chart_type, symbol, yAxis=idx, dataGrouping={}, turboThreshold=0) H.set_dict_options(options) H.add_JSscript(self.theme, "head") for js_source in js_sources: H.add_JSsource(js_source) return H
""" This example generates a candlestick chart, which updates (async loading) when a different time period is selected by the navigation bar due to the large dataset. Due to the update, this chart requires JS function in the beginning and xAxis.events options. """ from highcharts import Highstock H = Highstock() data_url = 'http://www.highcharts.com/samples/data/from-sql.php?callback=?' H.add_data_from_jsonp(data_url, 'json_data', 'candlestick', dataGrouping = {'enabled': False}) script = """json_data = [].concat(json_data, [[Date.UTC(2011, 9, 14, 19, 59), null, null, null, null]]);""" H.add_JSscript(script, 'head') H.add_navi_series_from_jsonp() # not really useful, but it shows in highstock demo options = { 'chart' : { 'zoomType': 'x' }, 'navigator' : { 'adaptToUpdatedData': False, }, 'scrollbar': { 'liveRedraw': False },
def plot(self, title=False, width=600, height=300, load_js=None, js_sources=[]): chart_height = (height + 50) * 1 - 50 + 200 H = Highstock(width=width, height=chart_height) groupingUnits = [ ['hour', [60]], ] with open( os.path.join(os.path.dirname(os.path.abspath(__file__)), "files/load.jinja")) as f: load_tempate = jinja2.Template(f.read()) options = { 'rangeSelector': { 'buttons': [{ 'type': 'minute', 'count': 180, 'text': '3h' }, { 'type': 'minute', 'count': 360, 'text': '6h' }, { 'type': 'minute', 'count': 720, 'text': '12h' }, { 'type': 'minute', 'count': 60 * 24, 'text': '1d' }, { 'type': 'minute', 'count': 60 * 48, 'text': '2d' }, { 'type': 'second', 'count': 1, 'text': '1s' }, { 'type': 'second', 'count': 10, 'text': '10s' }], 'selected': 4, 'inputEnabled': False }, 'plotOptions': { 'series': { 'turboThreshold:': 0, 'dataGrouping': { 'enabled': False, }, 'animation': False } }, 'navigator': { 'enabled': True, 'height': 20 }, 'chart': { 'animation': False, }, 'legend': { 'enabled': True, }, 'yAxis': [], 'title': { 'text': '', 'style': { 'display': 'none' } }, } if title: options['title'] = {'text': title} if load_js: load_js = load_tempate.render(symbols=self.symbols) options['event']['load'] = load_js symbol_data = {} for idx, (symbol, data) in enumerate(self.symbols): symbol_data[symbol] = data options['yAxis'].append({ 'labels': { 'align': 'right', 'x': -3 }, 'title': { 'text': 'y' }, 'lineWidth': 2, 'offset': 0, }) H.add_data_set(data, 'line', symbol, dataGrouping={}) H.set_dict_options(options) H.add_JSscript(self.theme, "head") for js_source in js_sources: H.add_JSsource(js_source) return H
by the navigation bar due to the large dataset. Due to the update, this chart requires JS function in the beginning and xAxis.events options. """ from highcharts import Highstock H = Highstock() data_url = 'http://www.highcharts.com/samples/data/from-sql.php?callback=?' H.add_data_from_jsonp(data_url, 'json_data', 'candlestick', dataGrouping={'enabled': False}) script = """json_data = [].concat(json_data, [[Date.UTC(2011, 9, 14, 19, 59), null, null, null, null]]);""" H.add_JSscript(script, 'head') H.add_navi_series_from_jsonp( ) # not really useful, but it shows in highstock demo options = { 'chart': { 'zoomType': 'x' }, 'navigator': { 'adaptToUpdatedData': False, }, 'scrollbar': { 'liveRedraw': False }, 'title': {