2

I would like to make streaming line graph but I could not understand how to implement bokeh periodic callback. I checked the given examples (1 and 2) for ColumnDataSource update using update function but I could not understand.

I would like to get data from database and plot (each time new data periodically). Could you please give me a very simple example?

import sqlite3
import time
import datetime
import time, threading
from dateutil import parser

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import column

p = figure(plot_width=800, plot_height=200)
p2 = figure(plot_width=800, plot_height=200)

conn = sqlite3.connect('data.db')
c = conn.cursor()

p_time = datetime.datetime.now() - datetime.timedelta(minutes=15)
c.execute('SELECT Date_Time, Inactive_Time, signal FROM PlotData WHERE Interface=(?) AND Date_Time>(?)',('wlan0',p_time,))
data = c.fetchall()
xs = []
ys = []
zs = []
for row in data:
    xs.append(parser.parse(row[0]))
    ys.append(row[1])
    zs.append(row[2])
p.line(xs, ys, line_width=2)
p2.line(xs, zs, line_width=2)

curdoc().add_root(column(p,p2))
double-beep
  • 5,031
  • 17
  • 33
  • 41
ryback
  • 21
  • 4
  • Have you tried add_periodic_callback(callback, period_milliseconds). See: http://stackoverflow.com/a/38294157/2929207 – Pablo Reyes Mar 24 '17 at 02:34
  • yes I tried it but I couldn't make it. I also checked OHLC example for it but I couldn't understand exactly how to update ColumnDataSource. if I understand it in a simple example, I can try to implement it to my code. https://github.com/bokeh/bokeh/blob/master/examples/app/ohlc/main.py @PabloReyes – ryback Mar 24 '17 at 09:13
  • 1
    Hi Pablo, it works right now. I used ColumnDataSource as it is used in OHLC example and periodic callback but I update the data as it is given in the "sliders" example ( https://github.com/bokeh/bokeh/blob/master/examples/app/sliders.py#L66 ). It updates the all data instead of appending which is given in OHLC. I hope this helps someone else so I wanted to share. @PabloReyes – ryback Mar 25 '17 at 14:26

0 Answers0