我正在嘗試使用jqplot與jquery mobile,牽線木偶和requirejs。我已經囊括了所有jqplot需要CSS,以及在head標籤的腳本文件,但是當我嘗試使用下面的代碼Jqplot不與requirejs,jquerymobile,木偶
define([ 'plot' ],
function() {
console.log("Success..Inside Offer Page Script.");
console.log("Plot..."+$.jqplot);
$.jqplot.config.enablePlugins = true;
var s1 = [ 2, 6, 7, 10 ];
var ticks = [ 'a', 'b', 'c', 'd' ];
plot1 = $.jqplot('chart1', [ s1 ], {
seriesDefaults : {
renderer : $.jqplot.BarRenderer,
pointLabels : {
show : true
}
},
axes : {
xaxis : {
renderer : $.jqplot.CategoryAxisRenderer,
ticks : ticks
}
},
highlighter : {
show : false
}
});
});
繪製圖表它給了我這樣的錯誤
Uncaught TypeError: undefined is not a function jqplot.barRenderer.js:41
(line 41: $.jqplot.BarRenderer.prototype = new $.jqplot.LineRenderer();)
Uncaught TypeError: Cannot call method 'push' of undefined jqplot.pointLabels.js:377
(line 377: $.jqplot.postSeriesInitHooks.push($.jqplot.PointLabels.init);)
中的情節我的上述代碼的定義是
define([
'../scripts/ext_libs/jquery.jqplot', 'jquery'
],
function() {
var plot;
require([
'../scripts/ext_libs/jqplot.barRenderer',
'../scripts/ext_libs/jqplot.pointLabels',
'../scripts/ext_libs/jqplot.categoryAxisRenderer',
],
function() {
plot = $.jqplot;
});
return plot;
} );
任何人都可以請幫助我如何解決這些錯誤?
在此先感謝。
不要你必須把'在.js'擴展陳述事實文件結尾。 我認爲它無法找到barRenderer的代碼。 – Gyandeep
@Gyandeep感謝您的回覆,但requirejs已經假定給定的路徑只包含js文件。所以它不是必需的。 – Rachna
因爲當我運行你的代碼它運行良好,我使用純JavaScript。我認爲你的包含文件存在一些問題。 – Gyandeep