我是JavaScript和Dojo的新手,所以请耐心等待。我正在尝试使用DataSeries对象创建一个饼图,如下所示:
var skillStore = new dojo.data.ItemFileReadStore({
url: "/data/skillhead.json"
});
function formatPieChartData(store, item) {
var tooltips = {
AVAILABLE: "Available agents",
ONACD: "Agents on ACD calls",
INACW: "Agents in ACW",
INAUX: "Agents in AUX",
AGINRING: "Agents with ringing phones",
OTHER: "Agents otherwise occupied",
};
var ivalue = store.getValue(item, "value");
var legend = store.getValue(item, "legend");
var tooltip = tooltips[store.getValue(item, "field")];
var o = { y: ivalue, legend: legend, tooltip: tooltip }
return o;
}
/* This is how the data looks like after massaging
var chartData = [
{ y: 10, legend: "AVAIL", tooltip: "Available agents" },
{ y: 20, legend: "ONACD", tooltip: "Agents on ACD calls" },
{ y: 30, legend: "INACW", tooltip: "Agents in ACW" },
{ y: 40, legend: "INAUX", tooltip: "Agents in AUX" },
{ y: 50, legend: "INRING", tooltip: "Agents with ringing phones" },
{ y: 60, legend: "OTHER", tooltip: "Agents otherwise occupied" }
];
*/
var series = new dojox.charting.DataSeries(skillStore,
{ query: {
field: new RegExp("INACW|INAUX|AGINRING|OTHER|" +
"AVAILABLE|ONACD")
} },
formatPieChartData);
dojo.addOnLoad( function() {
chart = new dojox.charting.Chart("chartNode");
chart.setTheme(dojox.charting.themes.PrimaryColors);
chart.addPlot("default", {
type: "Pie",
radius: 85,
labels: false,
ticks: false,
markers: false
});
chart.addSeries("default", series);
var highlight = new dojox.charting.action2d.Highlight(chart, "default");
var tip = new dojox.charting.action2d.Tooltip(chart, "default");
grid.startup();
chart.render();
legend = new dojox.charting.widget.Legend({
chart: chart,
horizontal: false,
style: "font-size: 11px;",
},
"chartLegend");
legend.startup();
setTimeout(function(){ legend.refresh() }, 1000);
});
它工作正常,除了一件事:我不喜欢固定的超时。我必须在加载数据后刷新图例,否则不会显示;但是我不知道要附加哪个事件以便在获取数据后立即刷新图例。我看到DataSeries类有onFetchError事件但没有onFetchSuccess事件。我怎么知道数据已成功加载?
答案 0 :(得分:1)
我知道这已经很晚了,但无论如何我都会发帖,以防有人遇到同样的问题。我查看了DataSeries.js,他们使用了一个未记录的钩子。我不能保证你会在整个api更新中保持不变,它看起来像是:
dojo.connect(dataSeries, "_onFetchComplete", myObj, "myFunction");