使用 GWT 可视化显示多个图表
这段代码(如下)可以在屏幕上毫无意外地显示 1..n 个折线图。我想知道的是它的效率如何。我每次都会调用 VisualizationsUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE)
。一定要这样吗?
public void getData(List<GraphWrapper> graphWrapperList) {
for (GraphWrapper graphWrapper : graphWrapperList) {
populateResources.populateResourcesService(graphWrapper.getSeriesWrapperList(),
new AsyncCallback<GraphWrapper>() {
public void onFailure(Throwable caught) {
displayDialogBox("*** An Error Occurred ***", caught.toString());
}
public void onSuccess(final GraphWrapper response) {
Runnable onLoadCallback = new Runnable() {
private Widget chart;
public void run() {
this.chart = new LineChart(createTable(response), createOptions(response));
graphPanel.add(this.chart);
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
}
});
}
}
This bit of code (below) works to display 1..n LineCharts on the screen without incident. What I'm wondering is how efficient it is. I'm calling the VisualizationsUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE)
every time. Must it be done in this way?
public void getData(List<GraphWrapper> graphWrapperList) {
for (GraphWrapper graphWrapper : graphWrapperList) {
populateResources.populateResourcesService(graphWrapper.getSeriesWrapperList(),
new AsyncCallback<GraphWrapper>() {
public void onFailure(Throwable caught) {
displayDialogBox("*** An Error Occurred ***", caught.toString());
}
public void onSuccess(final GraphWrapper response) {
Runnable onLoadCallback = new Runnable() {
private Widget chart;
public void run() {
this.chart = new LineChart(createTable(response), createOptions(response));
graphPanel.add(this.chart);
}
};
VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过加载
LineChart.PACKAGE
,您只能使用单一类型的图表 (LineChart
)。由于您一次只能加载一个“包”,因此您不得不做出这个决定。尝试一下:使用
CoreChart
包,您可以加载任何CoreChart
子项(折线图、条形图、饼图、面积图、柱形图和散点图)。您还可以加载任意数量/组合的图表。此外,您无需每次都调用loadVisualizationApi(...)
方法,只需在第一次创建图表时调用即可。此后每个人都将使用该库。By loading the
LineChart.PACKAGE
, you're only allowed a single type of chart (LineChart
). Since you can only load a single "package" at a time, you're stuck with that decision. Try this:Using the
CoreChart
package, you can load anything that is a child ofCoreChart
(Line, Bar, Pie, Area, Column and Scatter). You can also load any number/combination of the charts. Additionally, you don't need to call theloadVisualizationApi(...)
method each time, but only the very first time you want to create a chart. Every one thereafter will use that library.我认为加载一次 LineChart 包就足够了。您是否尝试在回调中运行循环?
I think loading the LineChart package once should be enough. Did you try running the loop in the callback?