gpt4 book ai didi

javascript - D3 数据映射 : How to stack bubbles based on radius?

转载 作者:行者123 更新时间:2023-11-28 00:08:27 25 4
gpt4 key购买 nike

我正在使用 D3.js DataMaps 作为气泡 map 。我的 map 的问题是最大的气泡堆叠在所有其他气泡的顶部。我如何根据半径对这些气泡进行排序?

最佳答案

由于气泡数据是一个对象数组,您可以使用这样的自定义排序函数

myBubblesData.sort(function(a, b){ 
if (a.radius < b.radius) {
return 1;
}
if (a.radius > b.radius) {
return -1;
}
return 0;
});

要返回按相反顺序排序的对象,只需颠倒“1”和“-1”返回语句即可。

关于javascript - D3 数据映射 : How to stack bubbles based on radius?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31116823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com