简体   繁体   English

如何在一页上显示多个 D3 可视化?

[英]How to display multiple D3 visualizations on one page?

I'm having trouble displaying multiple D3 graphs on one page.我无法在一页上显示多个 D3 图表。 I have tried many things, but I can only seem to get one of the visualizations on the page, not both.我尝试了很多东西,但我似乎只能在页面上获得其中一个可视化,而不是两者。

For the first visualization in HTML, I have:对于 HTML 中的第一个可视化,我有:

<section id="first" class="main special">
<header class="major">
     <h2>Presidential Elections</h2>
</header>
<body>
     <div id="lineChart"></div>
     <script src="lineChart.js"></script>
</body>
</section>

My second visualization is similar in index.html:我的第二个可视化在 index.html 中类似:

<section id="second" class="main special">
<header class="major">
     <h2>House Seats Lost Based on Current President</h2>
</header>
<body>
     <div id="barChart"></div>
     <script src="barChart.js"></script>
</body>
</section>

In lineChart.js and barChart.js, I do not have either visualization labeled as 'svg', but instead 'lineChart' and 'barChart' respectively.在 lineChart.js 和 barChart.js 中,我没有将可视化标记为“svg”,而是分别标记为“lineChart”和“barChart”。 The current code displays only the first (line chart) visualization, but I found that when I remove <script src="lineChart.js"></script> , the first (line chart) visualization disappears and the second (bar chart) visualization becomes visible.当前代码仅显示第一个(折线图)可视化,但我发现当我删除<script src="lineChart.js"></script>时,第一个(折线图)可视化消失,第二个(条形图)可视化变得可见。 Does anyone have any idea or guidance on what I am doing wrong?有没有人对我做错了什么有任何想法或指导?

It's tough to say without seeing the code.不看代码很难说。 But you might selecting all svg s or div s and calling remove() .但是您可能会选择所有svgdiv并调用remove() Look for code that does that, and try dropping the remove() call.查找执行此操作的代码,然后尝试删除remove()调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM