繁体   English   中英

jqPlot:$ .jqPlot不是函数错误

[英]jqPlot : $.jqPlot is not a function error

我需要在网站上创建图表。

在我的HTML代码中,我创建了一个具有ID的div。

这是我的HTML代码:

<script src="/js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="/styles/jquery.jqplot.min.css" />
<script language="javascript" type="text/javascript" src="/js/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="/js/graph.js"></script>


<body>
    <div id="graph" style="height:400px;width:300px;></div> //i want to have my chart here
</body>

在js代码中,我只写了一个来自jqPlot官方网站的示例:

$(document).ready(function() {
    var chart_data = [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]];
    var chart_opt = {
        title:'Graph',
        axes:{yaxis:{min:-10, max:240}},
        series:[{color:'#5FAB78'}]
    };
    $.jqplot('graph', chart_data, chart_opt); 
});

所以我的问题是我在浏览器的控制台上出错:$ .jqplot不是一个函数

任何想法 ?

因为出现在$(document).ready(function()内的jqplot,所以出现了此错误,请尝试这样的操作。

 $(document).ready(function(){
   GetChart();
});


function GetChart(){
    var chart_data = [[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]];

    $('#graph').jqplot([chart_data], {
        title:'Default Bar Chart',
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer
        },
        axes:{
            xaxis:{
                renderer: $.jqplot.CategoryAxisRenderer
            }
        }
    });
    }

这是一个工作示例-https://jsfiddle.net/xrnfqax3/

为了使该示例正常工作,您需要将以下引用添加到您的项目中-

jquery.min.js
jquery.jqplot.js
jquery.jqplot.css
jqplot.barRenderer.js
jqplot.barRenderer.min.js
jqplot.categoryAxisRenderer.js
jqplot.categoryAxisRenderer.min.js

确保jquery-*。js的顺序在jqPlot.js之前。

并在所有脚本标签上使用language =“ javascript” type =“ text / javascript”。

最好的祝福

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM