I have the following codes to create chart graphics by dojox.charting:
function createChart() {
var node = dojo.byId("surfaceDiv");
while (node.hasChildNodes())
{
node.removeChild(node.lastChild); // remove all the children graphics
}
var nodes = "<div id='chart1' style='width: 10px; height: 10px;'></div><div id='legend1' ></div>";
dojo.html.set(node, nodes);
var nodeChart = dojo.byId("chart1");
var nodeLegend = dojo.byId("legend1");
var chart1 = new dojox.charting.Chart2D(nodeChart);
// set chart types and point series
chart1.render();
// now to add legend:
var legendNode = new dojox.charting.widget.Legent(
{chart: chart1}, nodeLegend.id));
}
The function works fine for the first call; however, if it is called again, the chart is displayed OK, but the legend is not displayed. In firebug, I noticed there is an error saying "Tried to register widget with id==legend1 but that id is already registered" in manager.xd.js (line 8). It looks like that somewhere in dojox's library cached the previous legend object with the same id.
I guess I have to clean any legend previously registered or cached. How can I do that?
By the way, in my html page, I have several ancor links to call JavaScript functions to draw different graphics in a div node with id="surfaceDiv", and the legend node" is the next div with id="legendDiv". Therefore, the above function can be called again.