[英]How to display the values from this array in the console of javascript?
如何在javascript中顯示給定數組的值? 換句話說,如何使用 console.log over "pie" 來顯示(42.9、37.9 和 19.2)?
它嘗試了 console.log(Object.values(pie)) 但沒有奏效。 非常感謝。
這就是我創建數組的方式:
var width = 350
height = 350
margin = 40
// The radius of the pieplot is half the width or half the height (smallest one). I subtract a bit of margin.
var radius = Math.min(width, height) / 2 - margin
// append the svg object to the div called 'my_dataviz'
var svg = d3.select("#my_dataviz_b")
.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var color =["#98abc5", "#8a89a6", "#7b6888"]
var annotations = ["Home win", "Draw game", "Away win"]
var data = d3.selectAll('.values_half_before').nodes();
var pie = d3.pie() //we create this variable, for the values to be readeable in the console
.value(function(d) {return d.innerHTML; })(data);
如果您想記錄數組的各個值,您可以使用 for 循環遍歷它們。
for (let i = 0; i < pie.length; i++) {
console.log(pie[i].value);
}
您也可以使用console.table
。 這將在一個漂亮的表格概覽中顯示這些值。
console.table(pie);
你可以這樣做:
pie.forEach((item) => {
console.log(item.value)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.