开发者

error :id is already registered

开发者 https://www.devze.com 2023-03-04 09:06 出处:网络
i have this error in my code Error: Tried to registe开发者_JS百科r widget with id==legend1 but that id is already registered

i have this error in my code

Error: Tried to registe开发者_JS百科r 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?


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(); 


Somewhat odd but it appears from looking at the example that it needs to happen at onLoad instead of when the DOM full loads. Try this in the head 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


I too got the same issue, this helped me

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


You can try this as well:-

Aftter addSeries you can write:-

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

And while updating that after UpdatinSeries() you can write :

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

For using digit you have to include:

dojo.require("dijit.registry");

Hope it helps!


To get rid of it you should configure dojo loader in the header of the page with 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

精彩评论

暂无评论...
验证码 换一张
取 消