D3.js-DOM操作

SVG

DOM

追加 DOM 元素:append()

The selection.append() function accepts one of two types:

  • A string which is the name of an element to create, or
  • A function which is executed (applied on parent) and should return an element or HTML.
1
2
3
4
const label = document.createElement('div');
label.style = `position:absolute; width: 200px; height: 50px; left: 50px; top: 40px; background-color: rgba(0, 0, 100, 0.1);`;
label.innerHTML = `日期:2021.02.18<br/>股价:300元`;
divContainer.append(() => label);