1.统计(Statistics)
https://github.com/d3/d3/blob/master/API.md#statistics
方法 | 描述 |
---|---|
d3.min(array[, accessor]) | 最小值,可以传入一个asscessor ,相当于先调用array.map(accessor) ,再求最小值.相比Math.min ,其忽视null 等 |
d3.max(array[, accessor]) | 最大值 compute the maximum value in an array. |
d3.extent(array[, accessor]) | 最大值和最小值 compute the minimum and maximum value in an array. |
d3.sum(array[, accessor]) | 求和 compute the sum of an array of numbers. |
d3.mean(array[, accessor]) | 求均值 compute the arithmetic mean of an array of numbers. |
d3.median(array[, accessor]) | 求中位数 compute the median of an array of numbers (the 0.5-quantile). |
d3.quantile(array, p[, accessor]) | 求分位数 compute a quantile for a sorted array of numbers. |
d3.variance(array[, accessor]) | 求方法 compute the variance of an array of numbers. |
d3.deviation(array[, accessor]) | 求偏差 compute the standard deviation of an array of numbers. |
2.查找(Search)
https://github.com/d3/d3/blob/master/API.md#search
方法 | 描述 |
---|---|
d3.scan(array[, comparator]) | 线性扫描,返回最小元素的索引,默认升序,min 是返回最小值,而其是返回索引 |
d3.bisect | 同d3.bisectRight |
d3.bisectRight(array, x[, lo[, hi]]) | 返回插入值,在已排序的数组的位置,如果值相等,位置在右边 +1 |
d3.bisectLeft(array, x[, lo[, hi]]) | 返回插入值,在已排序的数组的位置,如果值相等,位置在左边 +0 |
d3.bisector(accessor) | d3.bisectLeft 和d3.bisectRight 的另一种使用方式 |
bisector.left(array, x[, lo[, hi]]) | bisectLeft, with the given comparator. |
bisector.right(array, x[, lo[, hi]]) | bisectRight, with the given comparator. |
d3.ascending(a, b) | 升序 |
d3.descending(a, b) | 降序 |
3.转换(Transformations)
https://github.com/d3/d3/blob/master/API.md#transformations
方法 | 描述 |
---|---|
d3.cross(a, b[, reducer]) | 计算数组的笛卡尔积,可以指定积 的形式 |
d3.merge(arrays) | 横向合并两个数组 |
d3.pairs(array[, reducer]) | 操作相邻的数组,默认是将两个相邻元素组合 |
d3.permute(array, indexes) | 根据索引排序 |
d3.shuffle(array[, start[, stop]]) | 随机重排数组 |
d3.ticks(start, stop, count) | 生成count 个start 到 stop (inclusive)之间等差为1的 数组,注意count 会四舍五入 |
d3.tickIncrement | generate representative values from a numeric interval. |
d3.tickStep(start, stop, count) | 返回刻度间的大小 |
d3.range([start, ]stop[, step]) | generate a range of numeric values. |
d3.transpose(matrix) | 矩阵(二维数组)转置 |
d3.zip | 纵向合并数组 |
4.Histograms
https://github.com/d3/d3/blob/master/API.md#histograms
方法 | 描述 |
---|---|
d3.histogram() | 创建直方图生成自 |
histogram(data) | 计算bins,x0 表示bin的下边界,x1 表示bin的上边界 |
histogram.value | specify a value accessor for each sample. |
histogram.domain | specify the interval of observable values. |
histogram.thresholds | specify how values are divided into bins. |
d3.thresholdFreedmanDiaconis | the Freedman–Diaconis binning rule. |
d3.thresholdScott | Scott’s normal reference binning rule. |
d3.thresholdSturges | Sturges’ binning formula. |
排序
升序
var arr = [3,2,1];
arr.sort(d3.ascending);
console.log(arr); //[1, 2, 3]
降序
var arr = [1,2,3];
arr.sort(d3.ascending);
console.log(arr); //[3,2,1]