2011-05-11 17 views
5

ho questo errore nel mio codiceerrore: ID è già registrato

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

il codice per la leggenda è:

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

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

    stackedAreaLegend.refresh(); 

come posso risolvere questo errore?

risposta

7

tenta di distruggere widget di prima di creare nuovo:

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

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

stackedAreaLegend.refresh(); 
1

Un po 'strano ma risulta dall'esaminare l'esempio che deve accadere in onLoad anziché quando il DOM carica completamente. Prova questo nella sezione head del codice HTML:

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

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

+0

grazie. Ho dojo.addOnLoad (makeObjects); dove makeObjects ha creato il grafico e il refresh. il mio problema è che l'unica cosa veramente aggiornata è il suggerimento. Il grafico aggiornato è disegnato sotto il div corretto e la leggenda scompare –

1

troppo ho avuto lo stesso problema, questo mi ha aiutato

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

0

Potete provare anche questo: -

aftter addSeries si può scrivere: -

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

E durante l'aggiornamento che dopo UpdatinSeries() è possibile scrivere:

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

Per utilizzare cifre è necessario includere:

dojo.require("dijit.registry"); 

Spero che sia d'aiuto!

0

per sbarazzarsi di esso è necessario configurare dojo loader nell'intestazione della pagina con parseOnLoad: vero parametro:

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