Search code examples
javascriptdependency-injectiondojotypeerror

Dependency Issue with Dojo -Uncaught TypeError: chart.addPlot is not a function


I am trying to add a Dojo/Dojox chart to my code, but I keep getting the error Uncaught TypeError: chart.addPlot is not a function. I am pretty sure this is a problem with the way I have set up my dependencies under define([...], function()..., but I don't see it. I have my dependencies set up like this:

define([
'dojo/_base/declare',
'dijit/_WidgetsInTemplateMixin',   
'dojo/io-query',
'dojo/query',
'dijit/MenuItem', 
....//Dependencies added for Pie Chart. See corresponding functions
'dojox/charting/Chart2D', 
'dojox/charting/plot2d/Pie',
'dojox/charting/action2d/Highlight',   
'dojox/charting/action2d/MoveSlice', 
'dojox/charting/action2d/Tooltip',
'dojox/charting/themes/PrimaryColors'
], function (declare, _WidgetsInTemplateMixin, BaseWidget, ... 
...Chart2D, Pie, Highlight, MoveSlice, Tooltip, dojoxTheme) 
{ 
/*jshint unused: true*/
return declare([BaseWidget, _WidgetsInTemplateMixin], {
 ...

As you can see my functions are in the same order: Chart2D, Pie, Highlight, MoveSlice, Tooltip, dojoxTheme. Further down in the code, I create a variable called chart by calling the constructor new Chart2D. I assumed that I would then be able to use any methods under it. .addPlot is a method of Chart2D.

 var c = domConstruct.create("div", {
      id: "Chart"
    }, domConstruct.create("div"));

 var chart = new Chart2D(c);

However when I try to use the following, I get the error thrown. Is there something I am missing back when I added my dependencies? Suggestions?

chart.addPlot("default", {
      type: "Pie",
      radius: 50,
      htmlLabels: true
    });

Solution

  • I just found the answer to my problem. It was indeed related to the order of the modules and function arguments. In a nutshell, here's the problem: When I listed my modules under define, they didn't line up with the function aliases/arguments below them. There were a few mods that didn't have function arguments listed, so I thought it would be ok as long as they were still 'technically' in chronological order. It was not. That's what caused the error. Once I moved them (see below), the problem was fixed. Hope this helps someone with similar issues. enter image description here