将图表添加到< div id =" whatever"> [英] Add a chart to <div id="whatever">

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

问题描述

 在RPC之后,我想通过DOM获取特定的非gwt生成的div来放置图表。最终VerticalPanel contentHome = new VerticalPanel(); 

// ...

public void onSuccess(String result){

if(result == null){
contentHome .add(新的HTML(无法从服务器加载内容。));
return;
}

contentHome.getElement()。setId(inner);
contentHome.add(新的HTML(结果));

Element el = DOM.getElementById(whatever);

LineChart lc = new LineChart();

el.appendChild(lc.asWidget()。getElement()); //< - 这不起作用
contentHome.add(lc.asWidget()); //< - works works
}
});

不知何故

  lc.asWidget()。getElement()

仅返回

 < div>< / div> 

如果我只将小部件添加到contentHome,它就可以工作。显示图表。



如果有人可以帮我解决这个问题,我会很高兴的。

编辑:



试过这个:

  contentHome .getElement()SETID( 内部)。 
contentHome.add(新的HTML(结果));

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

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

el.appendChild(html.getElement());

但它也不起作用。

解决方案

div /javadoc/latest/com/google/gwt/user/client/ui/HTMLPanel.htmlrel =nofollow> HTLMPanel



更新: $ 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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆