1 回答

TA貢獻1802條經驗 獲得超10個贊
單個=
符號就是一個任務。您pie
在 if 語句內進行覆蓋,并['0', '0', '0']
?計算結果為 true,因為它不是空數組。
我建議您盡早評估 if 語句。請考慮以下情況,您可以在其中更改 div 內的值以查看輸出變化:
var data = d3.selectAll('.values_half_before')
? .nodes();
if(data.every(function(d) { return d.innerHTML === '0'; })) {
? console.log('it is a null vector');
} else {
? console.log('it is not a null vector');
? var pie = d3.pie() //we create this variable, for the values to be readeable in the console
? ? .value(function(d) {
? ? ? return d.innerHTML;
? ? })(data);
? console.log('pie', pie)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<div class="values_half_before">0</div>
<div class="values_half_before">0</div>
<div class="values_half_before">0</div>
添加回答
舉報