gpt4 book ai didi

javascript - 为什么我的 d3.js 图像出现在错误的位置?

转载 作者:行者123 更新时间:2023-12-02 16:11:29 24 4
gpt4 key购买 nike

我一直在设计甘特图。 javascript 文件位于 html 正文中:

<body>
<section>
<div class="container">
<h1 class="arrow">Areas of Expertise</h1>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="http://static.mentful.com/gantt-chart-d3v2.js"></script>
<script type="text/javascript" src="js/gantt.js"></script>
</div>
</section>
</body>

但是,当我查看源代码时,svg 文件位于 section 标记之外:

<body>
<section>...</section>
<script>...</script>
<svg class="chart" width="777" height="827">...</svg>
</body>

我希望我的图表具有其所在容器的属性。它似乎没有这样做。这是我的图表的工作示例:http://jsbin.com/pigudeyovi/2/edit?html,output

为什么 .svg 位于 section 标记之外?

最佳答案

代码的位置对于决定其输出出现的位置并不重要 - D3 要求您明确指定向 DOM 添加新元素的位置。

在这种情况下,输出将始终出现在 body 元素的正下方。这是硬编码在甘特图库源代码中的,用户无法配置。要更改它,您需要更改库的源代码或自己移动 DOM 元素。

关于javascript - 为什么我的 d3.js 图像出现在错误的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com