Building a custom widget with dojox charting

253
3
03-08-2019 08:15 AM
NickHallal
New Contributor II

So, when I try to chart with dojox, creating an instance of Chart(id) requires an ID for a DOM node to know where to create the chart, I believe.  So, I can understand how this would work in the same document, but it seems best to keep the Widget.js file separate from the Widget.html file for functionality.  The only problem is, the HTML file doesn't seem to get loaded before the JavaScript file, meaning Chart('ChartNode') is called before <div id='ChartNode'></div> even exists, and if I use a DOMContentLoader or dom.ready() function to try and make it wait for the HTML file to load, then the code creating the chart doesn't run at all.  I'm relatively new to javascript, so is there something I'm missing in general, or is this a problem with the way the Webappbuilder runs widgets? 

Thanks!

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Nicholas,

   It depends on where in your widget lifecycle you are trying to access the html elements sound like you are try to do something in the postcreate or something. See the widget lifecycle doc. Try moving your code to create the chart to the startup.

Widget life cycle—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers 

0 Kudos
NickHallal
New Contributor II

Moving it to startup() worked excellently, thank you!!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos