先给大家注意一个坑:
如果用的是Bokeh嵌入的方式而不是Bokeh文档的话。
一定要注意自己的Bokeh库和在cdn下面请求的js/css库是否相同。
不然一定没有绘图成功的。
例如:我用的Conda管理我的库的。下载的Bokeh库为2.0.1版本
那我导入的bokeh版本也必须为2.0.1版本!
上代码:
index.html文件。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bokeh example</title>
<link rel="stylesheet" href="https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.css">
<link rel="stylesheet" href="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.css">
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.0.1.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.1.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.1.min.js"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-api-2.0.1.min.js"></script>
{{ script | safe }}
</head>
<h1>louki</h1>
<body>
{{ div | safe }}
</body>
polls.py文件
def index(request):
latest_headset_list = HeadsetInfor.objects.order_by('-headset_id')[:5]#获取数据,以及order_by排序
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
p.line(x, y, line_width=2)
plot = figure()
plot.circle([1, 2], [3, 4])
script, div = components(p, CDN)
context = {#把参数传递到模板文件中
'latest_headset_list': latest_headset_list,
'script':script,
'div':div,
}
return render(request, 'polls/polls/index.html', context)#快捷方式
页面什么的,自己django基础操作一下,通过这样,就可以在页面上嵌入一个bokeh的视图了。
相当于我用的仍然是python代码,但是操作的却是js之类的操作。这样就相当的方便。
不用再使用3D.js之类的库了。
找了一天,居然是库和版本不对齐。
一个框架方案记录:
服务器:Apache
前端ROM:django
数据库:MySQl
数据可视化:Bokeh