首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dojo 1.8图表编程教程错误

Dojo 1.8图表编程教程错误
EN

Stack Overflow用户
提问于 2012-10-16 16:53:41
回答 2查看 1.4K关注 0票数 1

我已经阅读了一些Dojo1.8教程,它们很棒,但在基本图表教程中遇到了一个bug。声明性示例运行良好,但编程式示例在尝试呈现图表时出现错误。

图表教程: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中的错误如下所示:"TypeError: invalid ' in‘operand t“

您需要下载dojox/gfx/path.js的非精简版本,并查看第191行,您将在其中看到以下代码片段:

代码语言:javascript
复制
if(t instanceof Array){
    this._collectArgs(_12,t);
  }else{
    if("x" in t&&"y" in t){
      _12.push(t.x,t.y);
    }
  }

我认为错误就是逻辑落入"if("x“in t&&"y”in t)“行的地方。

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-26 00:02:18

这似乎是教程中的一个错误,'labelOffset‘应该接受一个数字,但他们给了它一个字符串,因此它失败了,去掉引号就行了,请看这个论坛的帖子。Charting tutorial in 1.7 and 1.8

票数 1
EN

Stack Overflow用户

发布于 2012-10-16 17:40:05

对,我找到了bug的原因,但找不到解决办法。

它的labelOffset值是一个负数,想象一下!

因此,如果您将"-20“更改为"20”,则运行时不会出现错误。

完整的示例包括导致错误的负值...

代码语言:javascript
复制
<!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值设为正,一切都应该正常运行。

代码语言:javascript
复制
labelOffset: "20"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12910918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档