0

我在我的项目中导入 jqPlot 如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="javascript" type="text/javascript" src="../js/jqplot/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="../js/jqplot/jquery.jqplot.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../js/jqplot/jquery.jqplot.css" />
    <script type="text/javascript">
      $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
    </script>
  </head>
  <body>
    <div id="chartdiv" style="height:400px;width:300px; "></div>
  </body>
</html>

我在 Chrome 中打开了这个 html 页面,但是有一个错误信息:

$.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
未捕获的类型错误:无法调用未定义的方法“jqplot”

我不完全知道原因。

4

1 回答 1

2

jqplot 抛出异常:

Uncaught No plot target specified 

这意味着它无法找到您想要放置图表的位置,因为 DOM 尚未准备好。您可以通过在 jQuery 函数中包装对 jqplot 的调用来修复它

$(function(){
    $.jqplot('chartdiv', [[[1, 2],[3,5.12],[5,13.1],[7,33.6],[9,85.9],[11,219.9]]]);
});

示例: http: //jsfiddle.net/jaimem/6ds84/ ​</p>

于 2012-11-24T07:47:41.853 回答