[英]Using title to display tooltip on SVG object doesn't work when added dynamically in GWT
I am using GWT 2.6.1 (+ GWT Graphics) and trying to draw SVG objects and display a tooltip on each one as follows: 我正在使用GWT 2.6.1(+ GWT图形),并尝试绘制SVG对象并在每个对象上显示工具提示,如下所示:
Point point = new Point(100, 100);
Circle reading = new Circle(point.getX(), point.getY(), 3);
reading.setFillColor("#000");
final String infoTip = "120 bpm";
Element titleElement = DOM.createElement("title");
titleElement.setInnerText(infoTip);
reading.getElement().appendChild(titleElement);
Now although the SVG circle draws correctly, the tooltip doesn't work. 现在,尽管SVG圆正确绘制,但工具提示不起作用。 I tried pasting the generated html into a static html file and that works fine, so it is something to do with dynamically adding the title element to the circle I guess but don't know how to solve it. 我尝试将生成的html粘贴到静态html文件中,并且效果很好,所以这与将title元素动态添加到我猜想但不知道如何解决的圈子有关。
I have tried adding the title element inside a deferred action: 我尝试在延迟动作中添加title元素:
Scheduler.Get().ScheduleDeferred(...)
and I have tried adding it in the onLoad: 并且我尝试将其添加到onLoad中:
Event.sinkEvents(reading.getElement(), Event.ONLOAD);
Event.setEventListener(reading.getElement(), new EventListener(){});
but no luck. 但没有运气。
DOM.createElement()
will be creating elements in the HTML namespace. DOM.createElement()
将在HTML名称空间中创建元素。 Your <title>
element needs to be in the SVG namespace. 您的<title>
元素必须位于SVG命名空间中。
You will need to use native JS DOM methods to do that. 您将需要使用本机JS DOM方法来执行此操作。 See the answer by Jared Garst on this other question for how: 有关其他问题,请参见Jared Garst的答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.