Add a chart to <div id=“whatever”>

不打扰是莪最后的温柔 提交于 2019-12-11 06:34:14

问题


After an RPC I want to get a specific non-gwt-generated div via DOM to place a chart there.

  final VerticalPanel contentHome = new VerticalPanel();

  // ...

  public void onSuccess(String result) {

    if(result == null) {
      contentHome.add(new HTML("Could not load content from server."));
      return;
    }

    contentHome.getElement().setId("inner");
    contentHome.add(new HTML(result));

    Element el = DOM.getElementById("whatever");

    LineChart lc = new LineChart();

    el.appendChild(lc.asWidget().getElement());  // <-- this DOESN'T work
    contentHome.add(lc.asWidget());              // <-- this works
  }
});

Somehow

lc.asWidget().getElement() 

only returns

< div >< /div >

If I add the widget just to contentHome it works. The chart is displayed.

I shall be pleased if anyone could help me on this one

EDIT:

Tried this too:

    contentHome.getElement().setId("inner");
    contentHome.add(new HTML(result));

    Element el = DOM.getElementById("whatever");
    LineChart lc = new LineChart();

    HTML html = HTML.wrap(lc.asWidget().getElement());

    el.appendChild(html.getElement());

but it doesn't work either.


回答1:


Wrap the div in an HTLMPanel

Updated:

HTMLPanel panel = new HTMLPanel(result);
panel.add(lc, "whatever");


来源:https://stackoverflow.com/questions/15537527/add-a-chart-to-div-id-whatever

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!