使用 GWT 可视化显示多个图表

发布于 2024-12-17 05:35:11 字数 1240 浏览 0 评论 0原文

这段代码(如下)可以在屏幕上毫无意外地显示 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 技术交流群。

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

发布评论

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

评论(2

迟月 2024-12-24 05:35:11

通过加载 LineChart.PACKAGE,您只能使用单一类型的图表 (LineChart)。由于您一次只能加载一个“包”,因此您不得不做出这个决定。尝试一下:

VisualizationUtils.loadVisualizationApi(onLoadCallback, CoreChart.PACKAGE);

使用 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:

VisualizationUtils.loadVisualizationApi(onLoadCallback, CoreChart.PACKAGE);

Using the CoreChart package, you can load anything that is a child of CoreChart (Line, Bar, Pie, Area, Column and Scatter). You can also load any number/combination of the charts. Additionally, you don't need to call the loadVisualizationApi(...) method each time, but only the very first time you want to create a chart. Every one thereafter will use that library.

会发光的星星闪亮亮i 2024-12-24 05:35:11

我认为加载一次 LineChart 包就足够了。您是否尝试在回调中运行循环?

public void getData(List<GraphWrapper> graphWrapperList) {
Runnable onLoadCallback = new Runnable() {
    public void run() {
            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) {
                            private Widget chart;
                            this.chart = new LineChart(createTable(response), createOptions(response));
                            graphPanel.add(this.chart);                  
                        }
                });
            }
        }
    };
VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
}

I think loading the LineChart package once should be enough. Did you try running the loop in the callback?

public void getData(List<GraphWrapper> graphWrapperList) {
Runnable onLoadCallback = new Runnable() {
    public void run() {
            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) {
                            private Widget chart;
                            this.chart = new LineChart(createTable(response), createOptions(response));
                            graphPanel.add(this.chart);                  
                        }
                });
            }
        }
    };
VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文