[英]D3 DataMaps: How to stack bubbles based on radius?
I am using D3.js DataMaps for a Bubbles map. 我正在将D3.js DataMaps用于Bubbles地图。 The problem of my map is that the biggest bubble is stacked on top of every other bubble.
我的地图的问题是,最大的气泡堆叠在每个其他气泡的顶部。 How do i get to sort these bubbles based on the radius??
如何根据半径对这些气泡进行排序?
since the bubbles data is an array of objects you could use a custom sort function like this 由于气泡数据是对象数组,因此您可以使用像这样的自定义排序功能
myBubblesData.sort(function(a, b){
if (a.radius < b.radius) {
return 1;
}
if (a.radius > b.radius) {
return -1;
}
return 0;
});
to return the objects sorted in the opposite order, just reverse the '1' and '-1' return statements. 要返回以相反顺序排序的对象,只需反转“ 1”和“ -1”返回语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.