简体   繁体   English

D3 js用于不平衡数据的缩放比例

[英]D3 js what kind of scale to use for unbalanced data

I have to render few circles on which "r" attr depends on the input data. 我必须绘制一些圆圈,其中“ r”属性取决于输入数据。 The problem with input data is one of the value is so huge compared to rest of the data points that when i use scaleLinear | 输入数据的问题是,与其余数据点相比,值之一很大,以至于我使用scaleLinear | Pow | 战俘 Log with range 2 - 35 ; 记录范围2-35; all my circles have radius between 2 - 3 and only that few data points are radius 35. so what kind of scale can i use for such data for better visual ? 我所有的圆的半径都在2-3之间,只有很少的数据点的半径是35。那么我可以使用哪种比例缩放这些数据以获得更好的视觉效果?

You could maybe use d3.scaleQuantize . 您可能使用d3.scaleQuantize Here is the example provided by the documentation: 这是文档提供的示例:

var width = d3.scaleQuantize()
    .domain([10, 100])
    .range([1, 2, 4]);

width(20); // 1
width(50); // 2
width(80); // 4

Or you could write your own classification function. 或者,您可以编写自己的分类函数。 Something like this (with 3 classes here): 像这样(这里有3个类):

if input data < x => r = 2 如果输入数据<x => r = 2

else if x <= input data < y => r = 8 否则,如果x <=输入数据<y => r = 8

else (input data >=y) => r = 14 否则(输入数据> = y)=> r = 14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM