1

I want to display a jquery from a sparkline which is actually a bar graph.I am not able to view it.Also I am new to jquery,

$("#sparkline").sparkline([5,6,7,2,0,4,2,4], {
    type: 'bar',
    height: '300',
    barWidth: 20,
    barSpacing: 10,
    barColor: '#615c5a',
    nullColor: '#3366cc '});

This is the code of the page it also is compatible with jquery 1.10

<!DOCTYPE html>
            <html>
            <head>
            <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"></script>
            <script>
            $("#sparkline").sparkline([5,6,7,2,0,4,2,4], {
                type: 'bar',
                height: '300',
                barWidth: 20,
                barSpacing: 10,
                barColor: '#615c5a',
                nullColor: '#3366cc '});
            </script>
            </head>

            <body>
            <div id ="sparkline" />
            </body>
            </html>

To addon I have generated the code of sparkline from

http://omnipotent.net/jquery.sparkline/#s-news
4

2 回答 2

2

您的#sparkline元素尚未加载。尝试这个:

      $(document).ready(function(){
         $("#sparkline").sparkline([5,6,7,2,0,4,2,4], {
            type: 'bar',
            height: '300',
            barWidth: 20,
            barSpacing: 10,
            barColor: '#615c5a',
            nullColor: '#3366cc '});
        });

阅读:http
://api.jquery.com/ready/ 请注意,并非所有浏览器都喜欢这种语法:<div id ="sparkline" />. 改用这个:<div id ="sparkline" ></div>.

更新 我看到你也忘了包含sparklinejs 文件。您需要从此处下载它,然后将其上传到您的服务器并包含它,就像您包含 jQuery js 文件一样:

<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"></script>
<script src="jquery.sparkline.js"></script> 
于 2013-06-26T05:53:52.170 回答
1

看起来 sparkline.js 与 jquery-1.9.1.min.js 及更高版本不兼容。试试 jquery-1.8.3.min.js 效果很好

于 2014-08-28T07:04:52.787 回答