D3.js 使用类选择器的多个D3js图表

D3.js 使用类选择器的多个D3js图表,d3.js,D3.js,我有一个表,其中每一行都有一个百分比值,我想为每一行构建一个饼图 例如: <table> <thead> <tr><th>Activity type</th><th>Progress %</th></tr> </thead> <tbody> <tr><td>Live classes</td><td class="pie-

我有一个表,其中每一行都有一个百分比值,我想为每一行构建一个饼图

例如:

<table>
<thead>
    <tr><th>Activity type</th><th>Progress %</th></tr>
</thead>
<tbody>
    <tr><td>Live classes</td><td class="pie-chart">50</td></tr>
    <tr><td>Lessons</td><td class="pie-chart">70</td></tr>
</tbody>
</table>

我想知道是否有一种更简单/更好/更优雅的方法可以做到这一点。

为什么不能将饼图放入其中?您尝试了什么?我在单元格中添加了一个类,该类的数值
50
,并尝试使用D3.js用饼图替换这些数值。我可以通过单元格进行迭代,但不使用自动D3.js迭代。“我想知道是否有一种更简单的方法可以做到这一点。”拉斯克托夫我编辑了这个问题。请看我做了什么。您可以使用
d3.selectAll()
选择
td
元素,然后将饼图的数据绑定到它们并生成图表。因此您需要先提取数据。
var currentPie = d3.select('.pie-chart');

while ( currentPie[0][0] != null ) {
    // ... Code to create the pie chart.

    // Remove the class so the next item will be different.
    currentPie.attr('class', '');

    // Pick up the next pie chart to build.
    currentPie = d3.select('.pie-chart');
}