Hi All,
i am working on the example found at JavaScript callbacks — Bokeh 2.4.2 Documentation under Custom JS for Selections.
I have rewritten the code according my purpose but it’s not behaving as expected. My first goal is to try to replicate 100% the example above with daily OHLC candles. Once done I will try to display on the second chart an inferior time frame OHLC sample based on the range selected from the first chart.
Inspecting JS from the broser i get bokeh-0.12.11.min.js:sourcemap:30 [bokeh] could not set initial ranges
Here is my code,
any help much appreciated!
many thanks
Andrea
import bokeh.util.compiler
bokeh.util.compiler._npmjs = ‘npm.cmd’
import pandas as pd
from bokeh.plotting import figure, curdoc
from bokeh.models.tools import HoverTool, WheelZoomTool, PanTool
from bokeh import events
from bokeh.layouts import widgetbox, row, column
from bokeh.models.widgets.buttons import Button
from bokeh.embed import components
from bokeh.io import output_file, save, show
from bokeh.embed.standalone import file_html
from bokeh.core.properties import Instance, List
from bokeh.models.tools import Tap, Tool, LassoSelectTool
from bokeh.models.callbacks import CustomJS
from bokeh.models.sources import ColumnDataSource
from bokeh.models import BoxSelectTool, Rect, WheelZoomTool
from bokeh.events import DoubleTap
from bokeh.resources import CDN
def image_label_plot():
Ohlc_All = ImportingData()
df = Ohlc_All
#source_ohlc = ColumnDataSource( { ‘time’: df.time, ‘low’ : df.low, ‘high’ : df.high, ‘open’ : df.open, ‘close’ : df.close, ‘color’ : df.color } )
source_ohlc = ColumnDataSource( df )
source_ohlc2 = ColumnDataSource( { ‘time’: , ‘low’ : , ‘high’ : , ‘open’ : , ‘close’ : , ‘color’ : } )
plot = figure( x_axis_type = ‘datetime’, toolbar_location = ‘above’ )
plot_2 = figure( x_axis_type = ‘datetime’, toolbar_location = ‘above’ )
plot.segment(x0=‘time’, y0=‘low’, x1=‘time’, y1=‘high’, line_width=1, color=‘black’, source = source_ohlc)
plot.segment(x0=‘time’, y0=‘open’, x1=‘time’, y1=‘close’, line_width=3, color=‘color’, source = source_ohlc)
plot_2.segment(x0=‘time’, y0=‘low’, x1=‘time’, y1=‘high’, line_width=1, color=‘black’, source = source_ohlc2)
plot_2.segment(x0=‘time’, y0=‘open’, x1=‘time’, y1=‘close’, line_width=3, color=‘color’, source = source_ohlc2)
plot.add_tools(LassoSelectTool())
source_ohlc.callback = CustomJS(args=dict(s2=source_ohlc2), code="""
var inds = cb_obj.selected[‘1d’].indices;
var d1 = cb_obj.data;
var d2 = s2.data;
d2[‘time’] =
d2[‘open’] =
d2[‘low’] =
d2[‘high’] =
d2[‘close’] =
d2[‘color’] =
for (i = 0; i < inds.length; i++) {
d2[‘time’].push(d1[‘time’][inds[i]])
d2[‘open’].push(d1[‘open’][inds[i]])
d2[‘low’].push(d1[‘low’][inds[i]])
d2[‘high’].push(d1[‘high’][inds[i]])
d2[‘close’].push(d1[‘close’][inds[i]])
d2[‘color’].push(d1[‘color’][inds[i]])
}
s2.change.emit();
“”")
output_file(‘test.html’)
return column(plot,plot_2)
if name == ‘main’:
plot = image_label_plot()
show(plot)