# echarts-stat
**Repository Path**: yyy0118/echarts-stat
## Basic Information
- **Project Name**: echarts-stat
- **Description**: Statistics tool for ECharts
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 5
- **Forks**: 1
- **Created**: 2020-03-11
- **Last Updated**: 2024-07-26
## Categories & Tags
**Categories**: charting-components
**Tags**: None
## README
# ecStat
ecStat 是 [ECharts](https://github.com/ecomfe/echarts) 的统计和数据挖掘工具。你可以把它当作一个工具库直接用来分析数据;你也可以将其与 ECharts 结合使用,用 ECharts 可视化数据分析的结果。
同时支持 Node 和浏览器中使用。
*其他语言版本: [English](README.md), [简体中文](README.zh-CN.md).*
## 安装
如果你使用 npm ,直接运行下面的命令:
```sh
npm install echarts-stat
```
或者, 从 [dist](https://github.com/ecomfe/echarts-stat/tree/master/dist) 目录直接下载引用:
```html
```
## API
* [直方图](#histogram)
* [聚类](#clustering)
* [回归](#regression)
* [基本统计方法](#statistic)
### 直方图
直方图主要用来可视化数值型数据的分布情况。用以直观判断数值型数据的概率分布,是一种特殊类型的柱状图。构建直方图的第一步是将总的数值区间切割成一个个小的区间间隔,然后统计落入每个区间间隔中的数值样本个数,并且每个小区间间隔都是连续的、大小相等的、相互不重叠的,即 [[x0, x1), [x1, x2), [x2, x3]]。
#### 调用方式
```js
var bins = ecStat.histogram(data, binMethod);
```
##### 参数说明
* `data` - `Array`. 数值样本.
```js
var data = [8.6, 8.8, 10.5, 10.7, 10.8, 11.0, ... ];
```
* `binMethod` - `string`. 直方图提供了四种计算小区间间隔个数的方法,分别是 `squareRoot`, `scott`, `freedmanDiaconis` 和 `sturges`。这里的每个小区间间隔又称为 `bin`,所有的小区间间隔组成的数组称为 `bins`。当然,对于一个直方图来说,没有所谓的最佳区间间隔个数,不同的区间间隔大小会揭示数据样本不同的数值特性。
* `squareRoot` - 默认方法,Excel 的直方图中也是使用这个方法计算 `bins`。依照 [Square-root choice](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition) 返回 bin 的个数:
```js
var bins = ecStat.histogram(data);
```
* `scott` - 依照 [Scott's normal reference Rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition) 返回 bin 的个数:
```js
var bins = ecStat.histogram(data, 'scott');
```
* `freedmanDiaconis` - 依照 [The Freedman-Diaconis rule](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition) 返回 bin 的个数:
```js
var bins = ecStat.histogram(data, 'freedmanDiaconis');
```
* `sturges` - 依照 [Sturges' formula](https://en.wikipedia.org/wiki/Histogram#Mathematical_definition) 返回 bin 的个数:
```js
var bins = ecStat.histogram(data, 'sturges');
```
##### 返回值说明
* `bins` - `Object`. 返回值包含了每一个 bin 的详细信息,以及用 [ECharts](https://github.com/ecomfe/echarts) 绘制直方图所需要的数据信息。
* `bins.bins` - `Array.