本文介绍了将图表添加到< div id =" whatever">的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  



更新: $ b

HTMLPanel面板=新HTMLPanel(结果);
panel.add(lc,whatever);


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.

解决方案

Wrap the div in an HTLMPanel

Updated:

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

这篇关于将图表添加到&lt; div id =&quot; whatever&quot;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:38