问题
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