当我在 Ajax 调用后调用 updateSeries 时,为什么我的 Dojo 饼图消失了?
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑
eventByReasonsData
是一个字符串,而updateSeries()
需要一个数组。您可以使用 dojo.fromJson() 将字符串转换为数组:I suspect that
eventByReasonsData
is a string, whenupdateSeries()
expects an array. You can usedojo.fromJson()
to convert the string to an array: