【问题标题】:unable to draw graphs using Vis.js in tornado无法在龙卷风中使用 Vis.js 绘制图形
【发布时间】:2016-01-06 18:39:23
【问题描述】:

大家好,我正在尝试在 tornado 框架中使用 vis.js 绘制图形,但我无法实现如何引导文件,我现在在 url 中只得到 Helloworld 而不是图形 在此先感谢

enter code here Tornado
 import tornado.httpserver
 import tornado.ioloop
 import tornado.options
 import tornado.web
 import os


 from tornado.options import define, options

 define("port", default=8888, help="run on the given port", type=int)
 settings = {
"static_path": os.path.join(os.path.dirname(__file__), "static"),
"template_path":os.path.join(os.path.dirname(__file__), "templates"),
 }


 class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("graph.html")




 def main():
     tornado.options.parse_command_line()
     application = tornado.web.Application([
    (r"/", MainHandler),
    (r"/", tornado.web.StaticFileHandler,
 dict(path=settings['static_path'])),

],**settings)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    main() 

这里是 HTML

enter code here
 <html>
 <head>
 <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
 <meta content="utf-8" http-equiv="encoding">
 <title>Graph2d | Basic Example</title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript"src="{{ static_url("vis.js") }}"></script>
<link rel="stylesheet" href="{{ static_url("vis.css") }}"
<script src="../static/vis.js"></script>
<link href="../static/vis.css" rel="stylesheet" type="text/css" />
<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
<body>
<h1>helloworld</h1>
<div id="visualization"></div>
<script type="text/javascript">
var container = document.getElementById('visualization');
var items = [
{x: '2014-06-11', y: 10},
{x: '2014-06-12', y: 25},
{x: '2014-06-13', y: 30},
{x: '2014-06-14', y: 10},
{x: '2014-06-15', y: 15},
{x: '2014-06-16', y: 30}
  ];

var dataset = new vis.DataSet(items);
var options = {
start: '2014-06-10',
end: '2014-06-18'
  };
var graph2d = new vis.Graph2d(container, dataset, options);
</script>
</body>
</html>

【问题讨论】:

  • 你有什么错误?提供更多信息,因为您的代码再次按预期工作(使用 vis 4.11.0 测试)。有一些问题需要修复,即使它们一切正常,HTML 中的&lt;link&gt; 被错误地终止,并且您拥有与static_url 相同的资源(工作)并且没有......所有龙卷风/渲染都在工作。
  • 我在终端中找不到 404 vis,在 html 页面中我没有收到任何错误但是图表没有显示/部署@kwarunek
  • 我刚刚下载了 vis.js 我不知道它是哪个版本你能告诉我你做了什么以及为什么它在我的环境中不起作用??
  • 如果可能的话,请你展示你的程序:)
  • 我已经添加了答案 - 一步一步。

标签: javascript tornado vis.js


【解决方案1】:

我已经测试过,一切似乎都很好。确保您有静态目录。我是如何测试的

~$ virtualenv test
~$ source test/bin/activate  # activate virtualenv
~$ pip install tornado
~$ mkdir static
~$ mkdir templates
~$ wget https://cdnjs.cloudflare.com/ajax/libs/vis/4.11.0/vis.min.css -O static/vis.css
~$ wget https://cdnjs.cloudflare.com/ajax/libs/vis/4.11.0/vis.min.js -O static/vis.js
~$ # copy your HTML into templates/graph.html
~$ # copy your py into app.py
~$ python app.py
[I 160106 20:46:51 web:1946] 200 GET / (127.0.0.1) 7.46ms
[I 160106 20:46:51 web:1946] 200 GET /static/vis.js?v=1a407e3a47f81c53518823bd11369678 (127.0.0.1) 10.71ms
[I 160106 20:46:51 web:1946] 200 GET /static/vis.css?v=4e678a04d8440cf16f35838950d9d673 (127.0.0.1) 1.67ms

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 2015-09-23
    相关资源
    最近更新 更多