javascriptdojodojox.charting

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

the code for the legend is:

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

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

   stackedAreaLegend.refresh(); 

how i can solve this error?


Solution

  • Try to destroy widget before creating new:

    var stackedAreaLegend = dijit.byId('legend1');
    if (stackedAreaLegend) {
       stackedAreaLegend.destroyRecursive(true);
    }
    
    stackedAreaLegend = new dojox.charting.widget.SelectableLegend({
        chart: chart1
        }, "legend1");   
    
    stackedAreaLegend.refresh();