Question

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

    eventReasonsChart.render();


}

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

                chart.render();                                                 
            }

        }
    });

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?

Was it helpful?

Solution

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) );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top