Javascript – How to unregister legend in dojox.charting_ – Stack Overflow exchange rate of bitcoin

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 = ;

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).Exchange rate of bitcoin

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.

I think that is a bug in dojox.Charting.Widget.Legend(…). What I did was to clean all the graphics and legend dom elements under div surfacediv, and add new div chart1 for chart and div legend1 as legend. The chart works OK but not legend. I have the following anchor link call to the function in my html: ….

Curve chart

….

As a result, the function createchart() can be called more than once within the same web page session.Exchange rate of bitcoin the first time the chart and legend were displayed but the legend was missing in the subsequent calls or clicks.

To work around the problem or bug, I have to set legend ID dynamically with different values. Any cached legend id value within dojox.Charting.Widget.Legend(…) will not be conflict with new ids. Here is the codes: var legendcount = 0; // global value

Function createchart() {

Var node = dojo.ById(surfacediv);

While (node.HasChildNodes())

{

Node.RemoveChild(node.LastChild); // remove all the children graphics

}

Var legendid = legend + legendcount++;

Var nodes = +

; // set legend ID dynamically

Dojo.Html.Set(node, nodes);

Var nodechart = dojo.ById(chart1);

Var nodelegend = dojo.ById(legendid);

Var chart1 = new dojox.Charting.Chart2D(nodechart);

// set chart types and point series

Chart1.Render();

exchange rate of bitcoin

// now to add legend:

Var legendnode = new dojox.Charting.Widget.Legent(

{chart: chart1}, nodelegend.Id)); // no more conflict legend’s ID

}

I tested my codes and html page again. Legend is displayed every time!

The method I posted above is not a good way to resolve the issue. It is confirmed by a dojox’s insider that it is a bug in dojox.Charting based on my finding case. He does not recommend my way, removing HTML elements which I think for the chart and legend, as a solution.

I think his suggestion is right. The chart and legend are created by dojox.Charting apis. My case of html page may not reveal all the DOM objects to be removed just for the clean up. Some DOM objects in cache may be left uncleaned behind sense. For example, in JS codes, I added two divs under an empty div: one for chart and one for legend.Exchange rate of bitcoin dojox.Charting apis add svg nodes under the chart div and converted legend div to a table. In addition to that, several invisible divs are created outside my initial empty div. This cleaning up method would left some mess or cause unpredictable problems. Further more, my method may be broken in the future of new or updated dojox.Charting apis (fixing bugs as example).

Since I am new to dojox.Charting (just started to write some testing codes by its apis in the last week based on an article), I am not sure if dojox.Charting provides any way to clean up charts and legends? I think that would be best way or apis to do it if available.

Even my above solution works fine for my base, deleting all the chidlren nodesunder an empty div, you should be aware the potential problems.

All the demo codes, I can find out so far, are example codes to create or add new charts to a web page.Exchange rate of bitcoin there is no one, as far as I can tell, for updating, manipulating or simply refreshing charts. If the data series are coming from web services or REST, it would be a need just to update an area of charts. Here is an example of HTML page UP layout: curve chart ———————–

Pie chart | div area for chart |

Bar chart | |

Refresh chart with changes | |

———————–

With options available to create chart in one div area, I think I do have a need to clean up the div if there is any chart generated previously.

By looking at the codes how a chart and a legend are created by dojox.Charting apis: // nodedivforchart and nodedivforlegend are div nodes

Var chart1 = new dojox.Charting.Chart2D(nodedivforchart);

….

Var legend1 = new dojox.Charting.Widget.Legend(

{chart: chart1}, nodedivforlegend.Id);

exchange rate of bitcoin

My guess is that chart1 and legend1 are DOM instances or objects? Not sure if there is any way to destroy those instances as a way to clean up chart and legend? How?

Stack exchange

Network

• technology

• life / arts

• culture / recreation

• science

• other

• stack overflow

• server fault

• super user

• web applications

• ask ubuntu

• webmasters

• game development

• tex – latex

• software engineering

• unix & linux

• ask different (apple)

• wordpress development

• geographic information systems

• electrical engineering

• android enthusiasts

• information security

• database administrators

• drupal answers

• sharepoint

• user experience

• mathematica

• salesforce

• expressionengine® answers

• stack overflow em português

• blender

• network engineering

• cryptography

• code review

• magento

• software recommendations

• signal processing

exchange rate of bitcoin

• emacs

• raspberry pi

• stack overflow на русском

• programming puzzles & code golf

• stack overflow en español

• ethereum

• data science

• arduino

• bitcoin

More (28)

• photography

• science fiction & fantasy

• graphic design

• movies & TV

• music: practice & theory

• worldbuilding

• seasoned advice (cooking)

• home improvement

• personal finance & money

• academia

• law

More (16)

• english language & usage

• skeptics

• mi yodeya (judaism)

• travel

• christianity

• english language learners

• japanese language

• arqade (gaming)

• bicycles

• role-playing games

• anime & manga

• puzzling

• motor vehicle maintenance & repair

More (32)

• mathoverflow

• mathematics

• cross validated (stats)

• theoretical computer science

• physics

• chemistry

• biology

• computer science

• philosophy

More (10)

• meta stack exchange

exchange rate of bitcoin

• stack apps

• API

• data

• area 51