Error: id is already registered

I have this error in my code

Error: Tried to register widget with id==legend1 but that id is already registered

code for legend:

    <div id="legend1"></div>

    var stackedAreaLegend = new dojox.charting.widget.SelectableLegend({
    chart: chart1
    }, "legend1");   

   stackedAreaLegend.refresh(); 

How can I solve this error?

+5
source share
5 answers

Try to destroy the widget before creating a new one:

var stackedAreaLegend = dijit.byId('legend1');
if (stackedAreaLegend) {
   stackedAreaLegend.destroyRecursive(true);
}

stackedAreaLegend = new dojox.charting.widget.SelectableLegend({
    chart: chart1
    }, "legend1");   

stackedAreaLegend.refresh(); 
+7
source

A bit strange, but as you can see from the example, this should happen in onLoad, and not when loading the DOM. Try this in the main section of your HTML:

dojo.addOnLoad(function(){
  var stackedAreaLegend = dojox.charting.widget.SelectableLegend({chart: chart},"legend1");
  stackedAreaLegend.refresh();
});

Source: http://bugs.dojotoolkit.org/browser/dojox/trunk/charting/tests/test_selectableLegend.html?rev=23507

+1
source

,

var gridRegister = registry.byId('grid'); if (gridRegister) { gridRegister.destroyRecursive(true); }

+1

: -

Aftter addSeries : -

var legend = new dojox.charting.widget.Legend({ chart: chart, horizontal: false }, chartID);

UpdatinSeries() :

dijit.byId(chartID + "_Legend").refresh();

:

dojo.require("dijit.registry");

, !

0
source

To get rid of it, you must configure the dojo loader in the page header using the parseOnLoad: true parameter:

<script src="//yandex.st/dojo/1.9.1/dojo/dojo.js" data-dojo-config="isDebug: false, async: true, parseOnLoad: true"></script>
0
source

All Articles