1

我想使用这个 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]]  

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

4

1 回答 1

1

当我将 tkcip.js 固定为 tickp.js 时,它可以工作。请使用 webkit 检查器或 firebug 并使用 JSLint 检查 javascript 代码。由于缺少分号,它在 Internet Explorer 中出现语法错误。

我的意见.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

我的核心/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();
});
于 2011-12-06T07:34:57.307 回答