[英]How to display the values from this array in the console of javascript?
How can I display the values of the given array in javascript?如何在javascript中显示给定数组的值? In other words, how can use console.log over "pie" to display (42.9, 37.9 and 19.2)?换句话说,如何使用 console.log over "pie" 来显示(42.9、37.9 和 19.2)?
It tried console.log(Object.values(pie)) but it didn't work.它尝试了 console.log(Object.values(pie)) 但没有奏效。 Thanks a lot.非常感谢。
This is how I created the array:这就是我创建数组的方式:
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);
If you are looking to log individual values of your array you could loop over them with a for loop.如果您想记录数组的各个值,您可以使用 for 循环遍历它们。
for (let i = 0; i < pie.length; i++) {
console.log(pie[i].value);
}
You could also use console.table
.您也可以使用console.table
。 This will display the values in a nice table overview.这将在一个漂亮的表格概览中显示这些值。
console.table(pie);
You can do it this way:你可以这样做:
pie.forEach((item) => {
console.log(item.value)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.