如何将背景图像添加到使用 D3 创建的绘图中

Art*_*iga 2 javascript d3.js

我使用 D3 创建了这个折线图。

http://bl.ocks.org/d3noob/a22c42db65eb00d4e369

假设我需要将计算机本地文件中的一些 .png 图像添加到上图中,我该怎么做?

非常感谢。

she*_*hen 5

您可以像任何其他 HTML 标记一样background通过 CSS 向svg元素添加属性。例如,像这样你将在背景上有谷歌标志:

svg {
  background: url('https://www.google.nl/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png') no-repeat;
}
Run Code Online (Sandbox Code Playgroud)

有关您可以在后台使用的属性的更多信息,请访问 w3schools.com

  • 试试这个方法。`svg.style("background","url('https://www.google.nl/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png') no-repeat");` (3认同)