javascript - Why does my Dojo Pie chart disappear when i call updateSeries after an Ajax call? -
i trying update dojo pie chart using updateseries method. invoke method after performing ajax call updated javascript array data.
here javascript:
var eventbyreasonsdata = .... //gets populated on jsp page compile var theme = dojox.charting.themes.julie; var eventreasonschart = null; function makeeventsbyreason() { var dc = dojox.charting; eventreasonschart = new dc.chart2d("eventsbyreasonchart"); eventreasonschart.settheme( theme ).addplot("default", { type: "pie", font: "normal normal 8pt tahoma", fontcolor: "black", labeloffset: -20, radius: 100 }).addseries("eventseries", eventbyreasonsdata ); var anim_a = new dc.action2d.moveslice(eventreasonschart, "default"); var anim_b = new dc.action2d.highlight(eventreasonschart, "default"); var anim_c = new dc.action2d.tooltip(eventreasonschart, "default"); eventreasonschart.render(); }
here html:
<div id="eventsbyreasonchart" ></div>
and here javascript making ajax call:
new ajax.request( url, { method: 'post', parameters: params, oncomplete: function(response) { if( response.responsetext != "empty" ) { var chart = eventreasonschart; eventbyreasonsdata = response.responsetext; chart.updateseries( "eventseries", eventbyreasonsdata ); chart.render(); } } });
lastly, here how data formatted when being sent chart:
[{ y:48 },{ y:1 },{ y:1 },{ y:14 },{ y:7 },{ y:3 },{ y:8 }]
when chart drawn, cool, no problems. after making ajax call, receive new data, update call made , chart disappears. no errors can see on console.
any ideas?
i suspect eventbyreasonsdata
string, when updateseries()
expects array. can use dojo.fromjson()
convert string array:
chart.updateseries( "eventseries", dojo.fromjson(eventbyreasonsdata) );
Comments
Post a Comment