我正在使用Bokeh来绘制股价图表,该图表通过轮询json更新来更新。奇怪的是,在AjaxDataSource上使用“替换”模式时,折线图消失了。我可以说它仍然在那里,因为有一个HoverTool仍然可以在鼠标悬停时显示数据。一旦执行了第一次轮询并反馈了数据,该行就变得不可见。
# price ajax endpoint
def Data(request, ticker):
prices = RealtimeStockPrice.objects.filter(ticker=ticker).order_by('last_time')
x = []
y = []
for p in prices:
x.append(p.last_time.astimezone(timezone('US/Eastern')))
y.append(float(p.last_price))
return JsonResponse({'time': x, 'price': y})
# bokeh plotting code
p1 = figure(x_axis_type="datetime", title="Realtime {} Prices".format(signal.ticker))
source = AjaxDataSource(data_url=data_url, polling_interval=10000, mode='replace')
source.data = dict(time=times, price=prices)
# missing line:
p1.line(x='time', y='price', source=source, line_width=3, line_color='#22d18f')
# visible lines:
p1.line(static_times, trigger_price, line_width=2, line_dash='dotted', color='#e14646')
p1.line(static_times, open, line_width=2, line_dash='dotted', color='grey')
plot with the line invisible using 'replace'
当我将AjaxDataSource的mode ='replace'更改为mode ='append'时,该行再次可见。
plot with the line visible using 'append'
ajax更新是否有可能覆盖颜色或可见性/ alpha?对于调试此问题的任何建议,我也将不胜感激,因为我不知道如何获得对html canvas的了解。谢谢!
[如果有人看到了,我相信是因为Bokeh要求对距时间序列的ajax更新要自纪元:(]起以毫秒为单位)
https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/cK4MihXn7JMhttps://github.com/hhprogram/PyramidSite/blob/master/webgraphing/views/ajaxView.py
我能够在我的x轴上的所有datetime值上加上.timestamp(),并且可以正常工作。例如对于ajax端点
def Data(request, ticker):
prices = RealtimeStockPrice.objects.filter(ticker=ticker).order_by('last_time')
x = []
y = []
for p in prices:
x.append(p.last_time.astimezone(timezone('US/Eastern')).timestamp())
y.append(float(p.last_price))
return JsonResponse({'time': x, 'price': y})