相关疑难解决方法(0)

如何使用 d3.js 将 svg 附加到预先存在的 svg?

是否可以使用 d3.js 将另一个 svg 附加到预先存在的 svg 父级?

我知道可以通过使用“svg:image”属性来实现。但不幸的是,我失去了对内部 svg-child 的完全控制。

相关 dom 节点由 d3 创建,但未渲染,因此页面保持空白。

希望有人可以提供帮助,提前谢谢:)

这是我得到的:

网页CSS

  #svg-main-wrapper {
    position: absolute;
    min-width: 100%;
    min-height: 100%;
    bottom: 0;
    padding: 0;
    margin: 0;
  }
  
  
  <div id="svg-main-wrapper">
    <div svg-container svg-src="svgContainer[0].url" position="svgContainer[0].position">
    </div>    
  </div>
Run Code Online (Sandbox Code Playgroud)

JavaScript

angular.module('app', ['ui.bootstrap'])
  .directive('svgContainer', function() {
    return {
      restrict: 'A',
      template: function() {
        var parent = angular.element('body');
        return '<svg class="svg-container" width="' + parent.width() + '" height="' + parent.height() + '" viewBox=" 0 0 ' + parent.width() + ' ' …
Run Code Online (Sandbox Code Playgroud)

html javascript svg d3.js angularjs

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×1

d3.js ×1

html ×1

javascript ×1

svg ×1