1

I am using GWT 2.5 RC1 and GAE 1.7.2. I created a custom cell using UiRenderer Rendering HTML for Cells.
I want to render a chart using Google Chart Tools API for GWT Getting Started Using the Google Chart Tools with GWT
Below there is snippet of the render method, which does not work.

Does anybody know, how to render a google chart in a custom cell?

I would appreciate it, if he/she give me some directions or sample code. Thanks in advance.

    @Override
public void render(com.google.gwt.cell.client.Cell.Context context, Value value, final SafeHtmlBuilder sb) {
    final HTMLPanel test = new HTMLPanel("");
    Runnable onLoadCallback = new Runnable() {
    public void run() {
        //Panel panel = RootPanel.get();

        // Create a pie chart visualization.
        PieChart pie = new PieChart(createTable(), createOptions());

        pie.addSelectHandler(GoogleCharts.createSelectHandler(pie));
        test.add(pie);
        }
    };
    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);

    sb.appendHtmlConstant(test.getElement().getInnerHTML());
    renderer.render(sb);
}
4

1 回答 1

0

看起来你有一个竞争条件。当您调用 sb.appendHTMLConstant 时,测试元素可能为空,因为尚未触发 onLoadCallback。如果您将最后两行移动到回调的末尾,这将删除竞争条件。

@Override
public void render(com.google.gwt.cell.client.Cell.Context context, Value value, final SafeHtmlBuilder sb) {
    final HTMLPanel test = new HTMLPanel("");

    Runnable onLoadCallback = new Runnable() {
        @Override
        public void run() {
            // Create a pie chart visualization.
            PieChart pie = new PieChart(createTable(), createOptions());
            pie.addSelectHandler(GoogleCharts.createSelectHandler(pie));
            test.add(pie);

            sb.appendHtmlConstant(test.getElement().getInnerHTML());
            renderer.render(sb);
        }
    };

    // Load the visualization api, passing the onLoadCallback to be called
    // when loading is done.
    VisualizationUtils.loadVisualizationApi(onLoadCallback, PieChart.PACKAGE);
}
于 2012-10-08T01:23:22.237 回答