当我在 Ajax 调用后调用 updateSeries 时,为什么我的 Dojo 饼图消失了?

发布于 2024-10-05 04:18:36 字数 1768 浏览 3 评论 0原文

我正在尝试使用 updateSeries 方法更新 dojo 饼图。我在执行 ajax 调用后调用该方法以获取更新的 javascript 数组数据。

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


}

这是我的 HTML:

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

这是进行 AJAX 调用的 javascript:

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

        }
    });

最后,这是我的数据在发送到图表时的格式:

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

最初绘制图表时,一切都很酷,没有任何问题。进行 Ajax 调用后,我收到新数据,进行更新调用,图表消失。我在控制台上看不到任何错误。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2024-10-12 04:18:36

我怀疑 eventByReasonsData 是一个字符串,而 updateSeries() 需要一个数组。您可以使用 dojo.fromJson() 将字符串转换为数组:

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

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) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文