Why does my Dojo Pie chart disappear when i call updateSeries after an Ajax call?

I am trying to update a dojo Pie chart using the updateSeries method. I invoke the method after performing an ajax call to get an updated javascript array data.

Here is the 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");



Here is my HTML:

        <div id="eventsByReasonChart" ></div>

And here is the javascript making the 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 );



Lastly, here is how my data is formatted when being sent to the chart:

[{ y:48 },{ y:1 },{ y:1 },{ y:14 },{ y:7 },{ y:3 },{ y:8 }]

When the Chart is initially drawn, everything is cool, no problems. AFter making the Ajax call, i receive the new data, the update call is made and the chart disappears. No errors that I can see on the console.

any ideas?


I suspect that eventByReasonsData is a string, when updateSeries() expects an array. You can use dojo.fromJson() to convert the string to an array:

chart.updateSeries( "eventSeries", dojo.fromJson(eventByReasonsData) );

Need Your Help

Resharper and TortoiseSVN

svn tortoisesvn resharper visualsvn ankhsvn

Is there any good way to deal with the class renaming refactor from Resharper when the file is under source control and TortoiseSVN is the client. I have am trying VisualSVN right now but I haven'...

sympy simplifying fractional powers of imaginary number

python sympy

Why doesn't -(-1)**(1/3) + (-1)**(2/3) reduce to -1?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.