【发布时间】:2019-01-16 01:53:11
【问题描述】:
我已经看到此错误的多个化身,但没有看到与使用 Dojo API/CDN 直接相关的答案。我只是通过一个快速的 Dojo 图表教程来了解如何正确应用饼图。我正在使用简单的说明来设置一个可以用来从本地测试的网页(见下文)。每次我启动 .html 文件时,我都会收到错误 - Uncaught ReferenceError: require is not defined。之前的所有答案都指向src 有问题,无论是cdn、api 还是文件路径。我尝试了多种cdn和配置,包括src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"and
<script data-dojo-config="async: 1"
src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>`,
但我仍然遇到同样的错误(这些是直接来自文档)。关于导致此错误的原因以及如何解决它以测试我的简单饼图的任何建议?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial: Pie Chart!</title>
<script> src="//ajax.googleapis.com/ajax/libs/dojo/1.13.0/dojo/dojo.js"></script>
</head>
<body>
<script>
require([
'dojo/dom',
'dojo/dom-construct',
'dojox/charting/Chart',
'dojox/charting/themes/Claro',
'dojox/charting/PiePlot'
], function (dom, domConstruct, Chart, theme, PiePlot) {
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
});
// Add the series of data
pieChart.addSeries("January",chartData);
// Render the chart!
pieChart.render();
});
</script>
<div id="chartNode" style="width: 550px; height: 550px;"></div>
</body>
</html>
【问题讨论】:
标签: javascript html dojo require dojox.charting