2012-10-16 121 views
1

我一直在瀏覽一些Dojo 1.8教程,這些教程很棒,但在基本圖表教程中遇到了一個錯誤。聲明性示例正常工作,但編程示例在嘗試渲染圖表時發生錯誤。Dojo 1.8圖表編程教程錯誤

製圖教程:http://dojotoolkit.org/documentation/tutorials/1.8/charting/

工作的聲明例如:http://dojotoolkit.org/documentation/tutorials/1.8/charting/demo/basic-declarative.php

誤碼綱領性例如:http://dojotoolkit.org/documentation/tutorials/1.8/charting/demo/basic-programmatic.php

從我的調查,它看起來像問題是與代碼試圖用「IN」操作在一個字符串上,在這一點上,它跌倒了。

在Firebug的錯誤看起來是這樣的:「類型錯誤:無效‘在’操作數T」

你需要下載DojoX中/ GFX/path.js的非縮小的版本,看看行191,其中你會看到這個代碼片段:

if(t instanceof Array){ 
    this._collectArgs(_12,t); 
    }else{ 
    if("x" in t&&"y" in t){ 
     _12.push(t.x,t.y); 
    } 
    } 

我認爲錯誤是在邏輯落空到「如果(」「在T & &‘X’在T Y)」行。

任何想法?

+0

似乎給我一個錯字「...在t &&」y「中t)...」。請注意空白處。 – drcelus

+0

不錯的想法,我曾用同樣的想法嘗試過,但不幸的是它沒有任何區別。 – Jeremy

回答

1

似乎其在本教程中,「labelOffset」的錯誤應該採取一些,但他們給它一個字符串,因此它失敗了,把行情走和它的作品,看到這個論壇帖子。 Charting tutorial in 1.7 and 1.8

+0

謝謝你的發現Leona。 – Jeremy

1

對我找到了錯誤的原因,但不是補救措施。

它的labelOffset值是一個負數,很奇怪!

因此,如果您將「-20」更改爲「20」,它將毫無錯誤地運行。

完整的示例包括導致錯誤的負值...

<!DOCTYPE HTML> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <title>Demo: Basic Programmatic Chart</title> 
    <link rel="stylesheet" href="style.css" media="screen"> 
    <link rel="stylesheet" href="../../../resources/style/demo.css" media="screen"> 
    </head> 
    <body> 
    <h1>Demo: Basic Programmatic Chart</h1> 

    <!-- create the chart --> 
    <div id="chartNode" style="width: 550px; height: 550px;"></div> 

    <!-- load dojo and provide config via data attribute --> 
    <!-- load dojo and provide config via data attribute --> 
    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js"></script> 
    <script> 

    // x and y coordinates used for easy understanding of where they should display 
    // Data represents website visits over a week period 
    chartData = [ 
     { x: 1, y: 19021 }, 
     { x: 1, y: 12837 }, 
     { x: 1, y: 12378 }, 
     { x: 1, y: 21882 }, 
     { x: 1, y: 17654 }, 
     { x: 1, y: 15833 }, 
     { x: 1, y: 16122 } 
    ]; 

    require([ 
     // Require the basic 2d chart resource 
     "dojox/charting/Chart", 

     // Require the theme of our choosing 
     "dojox/charting/themes/Claro", 

     // Charting plugins: 

     //Require the Pie type of Plot 
     "dojox/charting/plot2d/Pie", 

     // Wait until the DOM is ready 
     "dojo/domReady!" 
     ], function(Chart, theme, PiePlot){ 

     // Create the chart within it's "holding" node 
     var pieChart = new Chart("chartNode"); 

     // Set the theme 
     pieChart.setTheme(theme); 

     // Add the only/default plot 
     pieChart.addPlot("default", { 
      type: PiePlot, // our plot2d/Pie module reference as type value 
      radius: 200, 
      fontColor: "black", 
      labelOffset: "-20" <-- bug value here 
     }); 

     // Add the series of data 
     pieChart.addSeries("January",chartData); 

     // Render the chart! 
     pieChart.render(); 

     }); 
    </script> 
    </body> 
</html> 

只是使labelOffset值正代替,一切都應該運行正常。

labelOffset: "20"