我试图根据从SQL查询中提取的数据,用HTML动态呈现bokeh图。在
我可以通过Jupyter制作图形并将它们呈现在单独的HTML文件中,但我很难从实际代码中实现这一点。在
这里是Jupyter的工作代码:
materialcode=cursor.fetchall()
for number in range(0,len(materialcode),1):
materialcode_list=materialcode[base_number+int(number)]['Material_Code']
with connection.cursor() as cursor:
sql = "Select Delivey_Date, Unit Price from report GROUP BY Delivey_Date";
with connection.cursor(pymysql.cursors.DictCursor) as cursor:
cursor.execute(sql)
linechart=cursor.fetchall()
df=pd.DataFrame(linechart)
x = df['Delivey_Date']
y = df['Unit Price']
p = figure(plot_width=750, plot_height=300, x_axis_type="datetime")
p.line(x, y, line_width=2)
p.title.text = df['Material_Name'][0]
output_file("line"+str(number)+".html")
show(p)
这将生成多个图,每个图都有自己的HTML文件(每个都会弹出一个新窗口)。 现在,我想呈现在我的HTML网页,所有的图形在网页上预定的位置一个接一个地在下面。在
对于一个图,除了以bokehjs脚本和script1=script1,div1=div1引用结尾外,这是一个简单的代码。在
^{pr2}$我无法理解的是如何在循环中包含脚本,以便使用自己的脚本引用自动呈现每个图形。我想一定有一种方法可以从Jupyter示例中构造出web页面所需的script1=script1,div1=div1的输出文件(“line”+str(number)+“.html”)。在
谢谢你的帮助。在
components
一次可以接受多个对象:有关详细信息,请参阅documentation。在
相关问题 更多 >
编程相关推荐