我已经阅读了一些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行,您将在其中看到以下代码片段:
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)“行的地方。
有什么想法吗?
发布于 2013-01-26 00:02:18
这似乎是教程中的一个错误,'labelOffset‘应该接受一个数字,但他们给了它一个字符串,因此它失败了,去掉引号就行了,请看这个论坛的帖子。Charting tutorial in 1.7 and 1.8
发布于 2012-10-16 17:40:05
对,我找到了bug的原因,但找不到解决办法。
它的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"https://stackoverflow.com/questions/12910918
复制相似问题