From c5759f027da65abee32f3867dd29199b95f6a655 Mon Sep 17 00:00:00 2001 From: Matt Chan Date: Fri, 26 Jun 2020 10:54:19 -0700 Subject: [PATCH] Adding time series tooltip. --- app.py | 8 -------- ticker.py | 7 ++++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 5b77b4aa5..4bf17e05d 100644 --- a/app.py +++ b/app.py @@ -23,23 +23,15 @@ def index(): if request.method == 'GET': # Default gives IBM's ticker when first loaded. app.vars['symbol'] = 'IBM' - p = create_ticker(app.vars['symbol']) - p_json = json.dumps(json_item(p, 'myplot')) return render_template('index.html', symbol=app.vars['symbol'], - p=p, - p_json=p_json, ) else: # User submitted a ticker symbol aka method = 'POST' app.vars['symbol'] = request.form['symbol'] - p = create_ticker(app.vars['symbol']) - json.dumps(json_item(p, 'myplot')) return render_template('index.html', symbol=app.vars['symbol'], - p=p, - p_json=p_json, ) diff --git a/ticker.py b/ticker.py index 9813745dc..78da601cc 100644 --- a/ticker.py +++ b/ticker.py @@ -60,6 +60,7 @@ def build_plot(symbol): color='olive', alpha=0.6, legend_label='Open', + name='Open', ) p.circle(df.index, df['Close'], @@ -67,21 +68,25 @@ def build_plot(symbol): color='orange', alpha=0.6, legend_label='Close', + name='Close', ) p.line(df.index, df['High'], line_width=2, color='steelblue', legend_label='High', + name='High', ) p.line(df.index, df['Low'], line_width=2, color='firebrick', legend_label='Low', + name='Low' ) p.xaxis.ticker = DatetimeTicker(desired_num_ticks=20) - hover = HoverTool(tooltips=[('Date', '@x{%F}'), + hover = HoverTool(tooltips=[('Time Series', '$name'), + ('Date', '@x{%F}'), ('Price', '$@y{0.00 a}'), ], formatters={'@x': 'datetime'})