Skip to content

Commit

Permalink
Adding time series tooltip.
Browse files Browse the repository at this point in the history
  • Loading branch information
thewchan committed Jun 26, 2020
1 parent 4ba9ebd commit c5759f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 0 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
7 changes: 6 additions & 1 deletion ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,33 @@ def build_plot(symbol):
color='olive',
alpha=0.6,
legend_label='Open',
name='Open',
)
p.circle(df.index,
df['Close'],
size=8,
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'})
Expand Down

0 comments on commit c5759f0

Please sign in to comment.