2011-08-25 128 views
3

此代碼工作完全正常:jqplot使用dateAxisRenderer行不渲染,有什麼想法爲什麼?

<div id="chart1"></div> 

然後我的JS:

在我看來

$(document).ready(function(){ 
    var plot1 = $.jqplot ('chart1', [[3,7,9,1,4,6,8,2,5]]); 
}); 

當我改變了我的JS(從jqPlot site複製),這樣我可以有包括我的x軸僅日期網格示出了沒有x軸或線(y軸是準確的和存在的話):

新js代碼能源部SNT工作:

$(document).ready(function(){ 

    var line1=[['2011-06-30 8:00AM',4], ['2011-7-30 8:00AM',6]]; 
    var plot2 = $.jqplot('chart1', [line1], { 
     title:'Customized Date Axis', 
     gridPadding:{right:35}, 
     axes:{ 
     xaxis:{ 
      renderer:$.jqplot.DateAxisRenderer, 
      tickOptions:{formatString:'%b %#d, %y'}, 
      min:'May 30, 2011', 
      tickInterval:'1 month' 
     } 
     }, 
     series:[{lineWidth:4, markerOptions:{style:'square'}}] 
    }); 
    }); 

注意我只改日期到2011年,改名爲一個div爲 「chart1」(如果相對於this jQPlot site),並加入jqplot.dateAxisRenderer.min.js的ID。

所以現在我有以下插件包括:

  • 「jqplot.canvasTextRenderer.min.js」
  • 「jqplot.canvasAxisLabelRenderer.min.js」
  • 「jqplot.dateAxisRenderer.min。 JS」
  • 「jqplot/jqplot.canvasAxisTickRenderer.min.js」
  • 「jqplot/jquery.jqplot.min.js」

我收到以下錯誤JS:

Uncaught TypeError: Cannot set property 'CanvasTextRenderer' of undefined in jqplot.canvasTextRenderer.min.js:30. 

Cannot set property 'CanvasTextRenderer' of undefined in jqplot.canvasAxisLabelRenderer.min.js:30. 

Cannot set property 'CanvasTextRenderer' of undefined in jqplot.dateAxisRenderer.min.js:30. 

Cannot set property 'CanvasTextRenderer' of undefined in jqplot.canvasAxisTickRenderer.min.js:30. 

我在做什麼錯在這裏?任何幫助將不勝感激。我搜索了兩個小時沒有成功。

回答

1

我創建了一個包含上面代碼中的普通的HTML頁面,它似乎工作。

<html> 
<head> 
    <link type="text/css" href="http://localhost/test1/atk4-addons/sterling/jqplot/templates/js/jqplot/jquery.jqplot.css" rel="stylesheet" /> 
    <script type="text/javascript" src="http://localhost/test1/atk4/templates/js/jquery-1.5.1.min.js"></script> 
    <script type="text/javascript" src="http://localhost/test1/atk4-addons/sterling/jqplot/templates/js/jqplot/jquery.jqplot.js"></script> 
    <script type="text/javascript" src="http://localhost/test1/atk4-addons/sterling/jqplot/templates/js/jqplot/plugins/jqplot.dateAxisRenderer.js"></script> 


    <script> 
    $(document).ready(function(){ 
    var line1=[['2011-06-30 8:00AM',4], ['2011-7-30 8:00AM',6]]; 
    var plot2 = $.jqplot('chart1', [line1], { 
    title:'Customized Date Axis', 
    gridPadding:{right:35}, 
    axes:{ 
     xaxis:{ 
     renderer:$.jqplot.DateAxisRenderer, 
     tickOptions:{formatString:'%b %#d, %y'}, 
     min:'May 30, 2011', 
     tickInterval:'1 month' 
     } 
    }, 
    series:[{lineWidth:4, markerOptions:{style:'square'}}] 
    }); 
    }); 
    </script> 

    </head> 
    <body> 
    <div id="chart1"></div> 
    </body> 
</html> 

其在Windows 7

output of jqplot code

我使用jQuery V1.5.1所以也許更新到最新版本,只是再試一次產生下面的輸出,我在Firefox 3.6.22以防萬一。

我只需要包含jquery.js,jqplot.js和dateAxisRenderer就可以工作,所以也嘗試刪除其他渲染器,因爲我不認爲您使用的任何選項都需要它在您提供的代碼示例中。

雖然這個代碼在隔離很好,我在其他地方瞭解一些瀏覽器不加載正確的順序加載和一切需要的CSS的JavaScript之前加載一個問題一個問題。

您與Ruby on Rails的,所以如果你是從一些框架代碼調用此標記這一點,它加載其他的東西爲好,說不定還有與順序,從而改變周圍可能有幫助的問題。

1

一種可能性是,jqPlot插件文件被加載jqPlot主要插件文件加載之前,導致「未定義」的錯誤。我遇到過你的問題,因爲我正在使用RequireJS異步加載依賴關係,並且jqPlot主插件文件與插件文件相比是巨大的,因此首先加載插件文件。

1

我也遇到過你的問題。有可能,腳本標記中有兩個「type」屬性?就像這樣:

<script type="javascript" type="text/javascript" src="/jqplot/jquery.jqplot.js"></script> 
0

做一個快速複製粘貼錯誤後,我注意到,如果源鏈接是<head></head>標籤外我得到這個錯誤。

<html> 
    <head> 
    <title>Awesome graph</title> 
    </head> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.logAxisRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script> 
<body>... 

替換head標籤中的標籤立即解決了這個問題。

<html> 
    <head> 
    <title>Awesome graph</title> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.logAxisRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.canvasAxisTickRenderer.min.js"></script> 
    <script type="text/javascript" src="jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script> 
    </head> 
<body>...