当我使用这个js库时,如何读取django中的某些数据?

发布于 2024-12-19 19:48:56 字数 1701 浏览 3 评论 0原文

我想使用这个 js Libarry(Tickp) 在 django 中制作股票图表。

我编写模板:

    <script type="text/javascript" src="/site_media/stats.js"></script>
        <script type="text/javascript" src="/site_media/tkcip.js"></script>   
                
 
<script>
    $(document).ready(function() {
        scrips = undefined;
        if($.browser.msie) {
            if($.browser.version < "9.0") { 
                var htmlstr = '<h5> Your browser \'IE : ' + $.browser.version + '\' does not support certain HTML 5 features natively, which we use. You won\'t be able to experience the full capabilities without those. Workarouns include - Using <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a> Plugin. To read more about \'Google Chrome Frame\' plugin, please read the following <a href="http://en.wikipedia.org/wiki/Google_Chrome_Frame"> article on Wikipedia</a>.' 
                $("#chart").html(htmlstr);
            }
        } 
            

        plot =  window.tickp("#chart") 
        plot.read({{ hisdata }}) 
        plot.plot()               
    });
    </script>

                  <div id="chart" >
               
                 
                  </div>   

然后测试 {{hisdata}} 格式,如下所示:

[[734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299], [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299], [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299]]

但浏览器中没有任何反应,我的代码有什么问题吗?

I want to use this js Libarry(Tickp) to make a stock chart in django.

and I write the template:

    <script type="text/javascript" src="/site_media/stats.js"></script>
        <script type="text/javascript" src="/site_media/tkcip.js"></script>   
                
 
<script>
    $(document).ready(function() {
        scrips = undefined;
        if($.browser.msie) {
            if($.browser.version < "9.0") { 
                var htmlstr = '<h5> Your browser \'IE : ' + $.browser.version + '\' does not support certain HTML 5 features natively, which we use. You won\'t be able to experience the full capabilities without those. Workarouns include - Using <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a> Plugin. To read more about \'Google Chrome Frame\' plugin, please read the following <a href="http://en.wikipedia.org/wiki/Google_Chrome_Frame"> article on Wikipedia</a>.' 
                $("#chart").html(htmlstr);
            }
        } 
            

        plot =  window.tickp("#chart") 
        plot.read({{ hisdata }}) 
        plot.plot()               
    });
    </script>

                  <div id="chart" >
               
                 
                  </div>   

and I test the {{hisdata}} format like this:

[[734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299], [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299], [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299]]  

but nothing happen in browser,what's wrong with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强辩 2024-12-26 19:48:56

当我将 tkcip.js 修复为 tickp.js 时,它起作用了。请使用 webkit 检查器或 firebug 并使用 JSLint 检查 javascript 代码。由于缺少分号,它在 Internet Explorer 中给出语法错误。

我的views.py:

from django.views.generic import TemplateView


class CoreIndex(TemplateView):
    template_name = 'core/index.html'

    def get_context_data(self, **kwargs):
        context = super(CoreIndex, self).get_context_data(**kwargs)
        context.update({
            'his_data': [
                [734472, 17.579999999999998, 17.649999999999999,17.309999999999999, 17.5, 14635299],
                [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299],
                [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299]
            ]
        })

        return context

我的core/index.html:

<html>
    <head>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/stats.js"></script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/tickp.js"></script>
        <script type="text/javascript">
            window.hisData = {{ his_data }}
        </script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/application.js"></script>
    </head>
    <body>
        <div id="chart"></div>
    </body>
</html>

我的application.js是:

$(document).ready(function() {
    if($.browser.msie) {
        if($.browser.version < "9.0") {
            var htmlstr = '<h5> Your browser \'IE : ' + $.browser.version + '\' does not support certain HTML 5 features natively, which we use. You won\'t be able to experience the full capabilities without those. Workarouns include - Using <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a> Plugin. To read more about \'Google Chrome Frame\' plugin, please read the following <a href="http://en.wikipedia.org/wiki/Google_Chrome_Frame"> article on Wikipedia</a>.';
            $("#chart").html(htmlstr);
        }
    }

    var plot = window.tickp("#chart");
    plot.read(window.hisData);
    plot.plot();
});

It works when i fixed tkcip.js as tickp.js. Please use webkit inspector or firebug and check javascript codes with JSLint. It gives syntax error in Internet explorer because of missing semicolons.

my views.py:

from django.views.generic import TemplateView


class CoreIndex(TemplateView):
    template_name = 'core/index.html'

    def get_context_data(self, **kwargs):
        context = super(CoreIndex, self).get_context_data(**kwargs)
        context.update({
            'his_data': [
                [734472, 17.579999999999998, 17.649999999999999,17.309999999999999, 17.5, 14635299],
                [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299],
                [734472, 17.579999999999998, 17.649999999999999, 17.309999999999999, 17.5, 14635299]
            ]
        })

        return context

my core/index.html:

<html>
    <head>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/stats.js"></script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/libs/tickp.js"></script>
        <script type="text/javascript">
            window.hisData = {{ his_data }}
        </script>
        <script type="text/javascript" src="{{ STATIC_URL }}js/application.js"></script>
    </head>
    <body>
        <div id="chart"></div>
    </body>
</html>

and my application.js is:

$(document).ready(function() {
    if($.browser.msie) {
        if($.browser.version < "9.0") {
            var htmlstr = '<h5> Your browser \'IE : ' + $.browser.version + '\' does not support certain HTML 5 features natively, which we use. You won\'t be able to experience the full capabilities without those. Workarouns include - Using <a href="http://code.google.com/chrome/chromeframe/">Google Chrome Frame</a> Plugin. To read more about \'Google Chrome Frame\' plugin, please read the following <a href="http://en.wikipedia.org/wiki/Google_Chrome_Frame"> article on Wikipedia</a>.';
            $("#chart").html(htmlstr);
        }
    }

    var plot = window.tickp("#chart");
    plot.read(window.hisData);
    plot.plot();
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文