django配置Bokeh库,进入数据可视化操作。

先给大家注意一个坑:
如果用的是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值