Search code examples
javascriptpythondatetimeadapterbokeh

Bokeh datetime via JS Adapter


I have a Ajax data source in Bokeh that returns me an Array of dates in Unix format. I want to convert them to this: "2020-4-28 13:39:10" and then plot the figure with the dates as x. Rightnow my adapter returns the values as string and I use a DatetimeTickFormatter:

fig.xaxis.formatter = DatetimeTickFormatter(seconds=["%d/%m/ %H:%M:%S"],
                                            minutes=["%d/%m/ %H:%M:%S"],
                                            minsec=["%d/%m/ %H:%M:%S"],
                                            hours=["%d/%m/ %H:%M:%S"])

to get the right format. But the Bokeh fig doesnt accept the string as a datetime object and I get an error: "[bokeh] could not set initial ranges".

How can I parse the data in a right format from the adapter to the figure? Thanks! I am using a python 3 flask application!


Solution

  • Bokeh fig doesnt accept the string as a datetime object

    Bokeh recognizes and uses only numbers as Unix timestamps. Every formatted date that you see is just a representation of that number.