• Stars
    star
    570
  • Rank 78,245 (Top 2 %)
  • Language
    HTML
  • Created over 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Statistics tool for Apache ECharts

ecStat

A statistical and data mining tool for Apache ECharts. You can use it to analyze data and then visualize the results with ECharts, or just use it to process data.

It works both in node.js and in the browser.

Read this in other languages: English, 简体中文.

Installing

If you use npm, you can install it with:

npm install echarts-stat

Otherwise, download this tool from dist directory:

<script src='./dist/ecStat.js'></script>
<script>

var result = ecStat.clustering.hierarchicalKMeans(data, clusterNumber, false);

</script>

If using bundler (like webpack, rollup, etc.), for example:

npm install echarts-stat
npm install echarts
import * as echarts from 'echarts';
import {transform} from 'echarts-stat';

echarts.registerTransform(transform.histogram);

var myChart = echarts.init(document.getElementById('main0'));

var option = {
    dataset: [{
        source: [
            [8.3, 143], [8.6, 214], [8.8, 251], [10.5, 26], [10.7, 86], [10.8, 93], [11.0, 176], [11.0, 39], [11.1, 221], [11.2, 188], [11.3, 57], [11.4, 91], [11.4, 191], [11.7, 8], [12.0, 196], [12.9, 177], [12.9, 153], [13.3, 201], [13.7, 199], [13.8, 47], [14.0, 81], [14.2, 98], [14.5, 121], [16.0, 37], [16.3, 12], [17.3, 105], [17.5, 168], [17.9, 84], [18.0, 197], [18.0, 155], [20.6, 125]
        ]
    }, {
        transform: {
            type: 'ecStat:histogram'
        }
    }],
    tooltip: {
    },
    xAxis: {
        type: 'category',
        scale: true
    },
    yAxis: {},
    series: {
        name: 'histogram',
        type: 'bar',
        barWidth: '99.3%',
        label: {
            show: true,
            position: 'top'
        },
        datasetIndex: 1
    }
};

myChart.setOption(option);

API Reference

Histogram

A histogram is a graphical representation of the distribution of numerical data. It is an estimate of the probability distribution of a quantitative variable. It is a kind of bar graph. To construct a histogram, the first step is to "bin" the range of values - that is, divide the entire range of values into a series of intervals - and then count how many original sample values fall into each interval. The bins are usually specified as consecutive, non-overlapping intervals of a variable. Here the bins(intervals) must be adjacent, and are of equal size.

Syntax

  • Used as echarts transform (since echarts 5.0)
    echarts.registerTransform(ecStat.transform.histogram);
    chart.setOption({
        dataset: [{
            source: data
        }, {
            type: 'ecStat:histogram',
            config: config
        }],
        ...
    });
  • Standalone
    var bins = ecStat.histogram(data, config);
    // or
    var bins = ecStat.histogram(data, method);
Parameter
  • data - number[] | number[][]. Data samples of numbers.

    // One-dimension array
    var data = [8.6, 8.8, 10.5, 10.7, 10.8, 11.0, ... ];

    or

    // Two-dimension array
    var data = [[8.3, 143], [8.6, 214], ...];
  • config - object.

    • config.method - 'squareRoot' | 'scott' | 'freedmanDiaconis' | 'sturges'. Optional. Methods to calculate the number of bin. There is no "best" number of bin, and different bin size can reveal different feature of data.

      • squareRoot - This is the default method, which is also used by Excel histogram. Returns the number of bin according to Square-root choice:

        var bins = ecStat.histogram(data);
      • scott - Returns the number of bin according to Scott's normal reference Rule:

        var bins = ecStat.histogram(data, 'scott');
      • freedmanDiaconis - Returns the number of bin according to The Freedman-Diaconis rule:

        var bins = ecStat.histogram(data, 'freedmanDiaconis');
      • sturges - Returns the number of bin according to Sturges' formula:

        var bins = ecStat.histogram(data, 'sturges');
    • config.dimensions - (number | string). Optional. Specify the dimensions of data that are used to regression calculation. By default 0, which means the column 0 and 1 is used in the regression calculation. In echarts transform usage, both dimension name (string) and dimension index (number) can be specified. In standalone usage, only dimension index can be specified (not able to define dimension name).

Return Value (only for standalone usage)
  • Used as echarts transform (since echarts 5.0)
    dataset: [{
        source: [...]
    }, {
        transform: 'ecStat:histogram'
        // // The result data of this dataset is like:
        // [
        //     // MeanOfV0V1, VCount, V0, V1, DisplayableName
        //     [  10,         212           8,  12, '8 - 12'],
        //     ...
        // ]
        // // The rest of the input dimensions that other than
        // // config.dimensions specified are kept in the output.
    }]
  • Standalone
    • result - object. Contain detailed messages of each bin and data used for ECharts to draw the histogram.
      • result.bins - BinItem[]. An array of bins, where each bin is an object (BinItem), containing three attributes:
        • x0 - number. The lower bound of the bin (inclusive).
        • x1 - number. The upper bound of the bin (exclusive).
        • sample - number[]. Containing the associated elements from the input data.
      • result.data - [MeanOfV0V1, VCount, V0, V1, DisplayableName][]. Used for bar chart to draw the histogram, where the length of sample is the number of sample values in this bin. For example:
        var bins.data = [
            // MeanOfV0V1, VCount, V0, V1, DisplayableName
            [  10,         212,          8,  12, '8 - 12'],
            ...
        ];
        // The rest of the input dimensions that other than
        // config.dimensions specified are kept in the output.
      • result.customData - [V0, V1, VCount][]. Used for custom chart to draw the histogram, where the length of sample is the number of sample values in this bin.

Examples

test/transform/histogram_bar.html

test/standalone/histogram_bar.html

histogram

Run

Clustering

Clustering can divide the original data set into multiple data clusters with different characteristics. And through ECharts, you can visualize the results of clustering, or visualize the process of clustering.

Syntax

  • Used as echarts transform (since echarts 5.0)
    echarts.registerTransform(ecStat.transform.clustering);
    chart.setOption({
        dataset: [{
            source: data
        }, {
            type: 'ecStat:clustering',
            config: config
        }],
        ...
    });
  • Standalone
    var result = ecStat.clustering.hierarchicalKMeans(data, config);
    // or
    var result = ecStat.clustering.hierarchicalKMeans(data, clusterCount, stepByStep);
Parameter
  • datanumber[][]. Two-dimensional numeric array, each data point can have more than two numeric attributes in the original data set. In the following example, data[0] is called data point and data[0][1] is one of the numeric attributes of data[0].

    var data = [
        [232, 4.21, 51, 0.323, 19],
        [321, 1.62, 18, 0.139, 10],
        [551, 11.21, 13, 0.641, 15],
        ...
    ];
  • config - object.

    • config.clusterCountnumber. Mandatory. The number of clusters generated. Note that it must be greater than 1.
    • config.dimensions - (number | string)[]. Optional. Specify which dimensions (columns) of data will be used to clustering calculation. The other columns will also be kept in the output data. By default all of the columns of the data will be used as dimensions. In echarts transform usage, both dimension name (string) and dimension index (number) can be specified. In standalone usage, only dimension index can be specified (not able to define dimension name).
    • config.stepByStepboolean. Optional. Control whether doing the clustering step by step. By default false.
    • config.outputType - 'single' | 'multiple'. Optional. Specify the format of the output. In "standalone" usage, it is by default 'multiple'. In "transform" usage, it can not be specified, always be 'single'.
    • config.outputClusterIndexDimension - (number | {index: number, name?: string}). Mandatory. It only works in config.outputType: 'single'. In this mode, the cluster index will be written to that dimension index of the output data. If be a number, it means dimension index. Dimension index is mandatory, while dimension name is optional, which only enables the downstream refer this dimension by name.
    • config.outputCentroidDimensions - (number | {index: number, name?: string})[] Optional. It only works in config.outputType: 'single'. If specify, the cluster centroid will be written to those dimensions of the result data. By default the centroids will not be written to the result data. If be a number, it means dimension index. Dimension index is mandatory, while dimension name is optional, which only enables the downstream refer this dimension by name.
Return Value

For example, the input data is:

var data = [
    // dimensions:
    // 0    1      2    3      4
    [ 232,  4.21,  51,  0.323, 'xxx'],
    [ 321,  1.62,  18,  0.139, 'xzx'],
    [ 551,  11.21, 13,  0.641, 'yzy'],
    ...
];

And we specify the config as:

config = {
    dimensions: [2, 3],
    outputClusterIndexDimension: 5
}

The result will be:

  • Used as echarts transform (since echarts 5.0)
    dataset: [{
        source: [ ... ],
    }, {
        transform: 'ecStat:clustering',
        config: {
            clusterCount: 6,
            outputClusterIndexDimension: 5,
            outputCentroidDimensions: [6, 7]
        }
        // The result data of this dataset will be:
        // [
        //    // dim2, dim3 are used in clustering.
        //    // All of the input data are kept in the output.
        //    // dim5 is the output cluster index.
        //    // dim6 is the output distance value.
        //    // dimensions:
        //    // 0    1      2    3       4       5   6   7
        //    [ 232,  4.21,  51,  0.323,  'xxx',  0,  14, 0.145 ],
        //    [ 321,  1.62,  18,  0.139,  'xzx',  2,  24, 0.321 ],
        //    [ 551,  11.21, 13,  0.641,  'yzy',  0,  14, 0.145 ],
        //    ...
        // ]
    }, {
        fromDatasetIndex: 1,
        fromTransformResult: 1
        // The result data of this dataset will be:
        // centroids: [
        //     // center of cluster0
        //     [14, 0.145],
        //     // center of cluster1
        //     [24, 0.321],
        //     ...
        // ]
    }]
  • Standalone
    • outputType: 'single':
      • result - object. For example:
        result = {
            data: [
                // dim2, dim3 are used in clustering.
                // All of the input data are kept in the output.
                // dim5 is the output cluster index.
                // dim6 is the output distance value.
                // dimensions:
                // 0    1      2    3      4      5  6
                [ 232,  4.21,  51,  0.323, 'xxx', 0, 89 ],
                [ 321,  1.62,  18,  0.139, 'xzx', 2, 23 ],
                [ 551,  11.21, 13,  0.641, 'yzy', 0, ?? ],
                ...
            ],
            centroids: [
                // center of cluster0
                [14, 0.145],
                // center of cluster1
                [24, 0.321],
                ...
            ]
        }
    • outputType: 'multiple':
      • resultobject. Including the centroids, and pointsInCluster. For example:
        result = {
            pointsInCluster: [
                // points in cluster0
                [
                    [ 232,  4.21,  51,  0.323, 'xxx' ],
                    [ 551,  11.21, 13,  0.641, 'yzy' ],
                    ...
                ],
                // points in cluster1
                [
                    [ 321,  1.62,  18,  0.139, 'xzx' ],
                    ...
                ],
                ...
            ],
            centroids: [
                // center of cluster0
                [14, 0.145],
                // center of cluster1
                [24, 0.321],
                ...
            ]
        };

Examples

You can not only do cluster analysis through this interface, but also use ECharts to visualize the results.

Note: the clustering algorithm can handle multiple numeric attributes, but for the convenience of visualization, two numeric attributes are chosen here as an example.

Directly visualize the final results of clustering

test/transform/clustering_bikmeans.html

test/standalone/clustering_bikmeans.html

static clustering

Run

Visualize the process of clustering

test/standalone/clustering_animation.html

dynamic clustering

Run

Regression

Regression algorithm can according to the value of the dependent and independent variables of the data set, fitting out a curve to reflect their trends. The regression algorithm here only supports two numeric attributes.

Syntax

  • Used as echarts transform (since echarts 5.0)
    echarts.registerTransform(ecStat.transform.regression);
    chart.setOption({
        dataset: [{
            source: data
        }, {
            type: 'ecStat:regression',
            config: {
                method: regressionType,
                ...opt
            }
        }],
        ...
    });
  • Standalone
    var myRegression = ecStat.regression(regressionType, data, opt);
    // or
    var myRegression = ecStat.regression('polynomial', data, order);
Parameters
  • regressionType - string. Mandatory. There are four types of regression, which are 'linear', 'exponential', 'logarithmic', 'polynomial'.
  • data - number[][]. Two-dimensional numeric array, Each data object should have two numeric attributes in the original data set. For Example:
    var data = [
        [1, 2],
        [3, 5],
        ...
    ];
  • opt - object.
    • opt.dimensions - (number | string)[] | (number | string). Optional. Specify the dimensions of data that are used to regression calculation. By default [0, 1], which means the column 0 and 1 is used in the regression calculation. In echarts transform usage, both dimension name (string) and dimension index (number) can be specified. In standalone usage, only dimension index can be specified (not able to define dimension name).
    • opt.order - number. Optional. By default 2. The order of polynomial. If you choose other types of regression, you can ignore it.
Return Value (only for standalone usage)
  • Used as echarts transform (since echarts 5.0)
    dataset: [{
        source: [...]
    }, {
        transform: 'ecStat:regression',
        // // The result of this dataset is like:
        // [
        //     // ValueOnX, ValueOnY
        //     [  23,       51      ],
        //     [  24,       62      ],
        //     ...
        // ]
        // // The rest of the input dimensions that other than
        // // config.dimensions specified are kept in the output.
    }]
  • Standalone
    • myRegression - object. Including points, parameter, and expression. For Example:

      myRegression.points = [
          // ValueOnX, ValueOnY
          [  23,       51      ],
          [  24,       62      ],
          ...
      ];
      // The rest of the input dimensions that other than
      // config.dimensions specified are kept in the output.
      
      // This is the parameter of linear regression,
      // for other types, it should be a little different
      myRegression.parameter = {
          gradient: 1.695,
          intercept: 3.008
      };
      
      myRegression.expression = 'y = 1.7x + 3.01';

Examples

You can not only do regression analysis through this interface, you can also use ECharts to visualize the results.

Linear Regression

test/transform/regression_linear.html

test/standalone/regression_linear.html

linear regression

Run

Exponential Regression

test/transform/regression_exponential.html

test/standalone/regression_exponential.html

exponential regression

Run

Logarithmic Regression

test/transform/regression_logarithmic.html

test/standalone/regression_logarithmic.html

logarithmic regression

Run

Polynomial Regression

test/transform/regression_polynomial.html

test/standalone/regression_polynomial.html

polynomial regression

Run

Statistics

This interface provides basic summary statistical services.

ecStat.statistics.deviation()

Syntax
var sampleDeviation = ecStat.statistics.deviation(dataList);
Parameter
  • dataList : number[]
Return Value
  • sampleDeviation: number. Return the deviation of the numeric array dataList. If the dataList is empty or the length less than 2, return 0.

ecStat.statistics.sampleVariance()

Syntax
var varianceValue = ecStat.statistics.sampleVariance(dataList);
Parameter
  • dataList : number[]
Return Value
  • varianceValue: number. Return the variance of the numeric array dataList. If the dataList is empty or the length less than 2, return 0.

ecStat.statistics.quantile()

Syntax
var quantileValue = ecStat.statistics.quantile(dataList, p);
Parameter
  • dataList : number[]. Sorted array of numbers.
  • p: number. where 0 =< p <= 1. For example, the first quartile at p = 0.25, the seconed quartile at p = 0.5(same as the median), and the third quartile at p = 0.75.
Return Value
  • quantileValue: number. Return the quantile of the sorted array of numbers. If p <= 0 or the length of dataList less than 2, return the first element of the sorted array dataList; if p >= 1, return the last element of the sorted array dataList; If dataList is empty, return 0.

ecStat.statistics.max()

Syntax
var maxValue = ecStat.statistics.max(dataList);
Parameter
  • dataList : number[]
Return Value
  • maxValue: number. The maximum value of the dataList.

ecStat.statistics.min()

Syntax
var minValue = ecStat.statistics.min(dataList);
Parameter
  • dataList : number[]
Return Value
  • minValue: number. The minimum value of the dataList.

ecStat.statistics.mean()

Syntax
var meanValue = ecStat.statistics.mean(dataList);
Parameter
  • dataList : number[]
Return Value
  • meanValue: number. The average of the dataList.

ecStat.statistics.median()

Syntax
var medianValue = ecStat.statistics.median(dataList);
Parameter
  • dataList : number[]. Sorted array of numbers
Return Value
  • medianValue: number. The median of the dataList.

ecStat.statistics.sum()

Syntax
var sumValue = ecStat.statistics.sum(dataList);
Parameter
  • dataList : number[]
Return Value
  • sumValue: number. The sum of the dataList.

More Repositories

1

vue-echarts

Vue.js component for Apache ECharts™.
JavaScript
9,615
star
2

echarts-for-weixin

基于 Apache ECharts 的微信小程序图表库
JavaScript
6,880
star
3

zrender

A lightweight graphic library providing 2d draw for Apache ECharts
TypeScript
5,816
star
4

fontmin

Minify font seamlessly
JavaScript
5,545
star
5

spec

This repository contains the specifications.
4,595
star
6

echarts-gl

Extension pack for Apache ECharts, providing globe visualization and 3D plots.
JavaScript
2,554
star
7

echarts-wordcloud

Word Cloud extension based on Apache ECharts and wordcloud2.js
JavaScript
1,592
star
8

echarts-liquidfill

Liquid Fill Chart for Apache ECharts
JavaScript
1,407
star
9

fonteditor

在线字体编辑器
JavaScript
1,297
star
10

awesome-echarts

Awesome list of Apache ECharts
1,269
star
11

veui

Enterprise UI for Vue.js.
JavaScript
1,057
star
12

esl

enterprise standard loader
JavaScript
834
star
13

react-hooks

Collection of react hooks
TypeScript
799
star
14

fontmin-app

fontmin as an OS X, Linux and Windows app
HTML
665
star
15

fecs

Front End Code Style Suite
JavaScript
643
star
16

edp

ecomfe develop platform
JavaScript
546
star
17

etpl

ETPL是一个强复用、灵活、高性能的JavaScript模板引擎,适用于浏览器端或Node环境中视图的生成。
JavaScript
496
star
18

okam

Mini program development framework
JavaScript
416
star
19

react-native-cn

407
star
20

est

EFE Styling Toolkit based on Less
Less
398
star
21

saber

移动 Web 解决方案
CSS
358
star
22

esui

enterprise simple ui library
JavaScript
340
star
23

er

enterprise ria framework
JavaScript
301
star
24

knowledge

Front-end knowledge hierarchy
CoffeeScript
236
star
25

reskript

一个帮助开发React应用的全功能命令行套件
TypeScript
210
star
26

rider

Rider 是一个基于 Stylus 与后处理器、无侵入风格的 CSS 样式工具库
CSS
205
star
27

echarts-map-tool

Map Tool for Apache ECharts
JavaScript
130
star
28

js-native

JavaScript
116
star
29

uioc

IoC Framework for us
JavaScript
115
star
30

eslint-config

eslint shareable config for efe
JavaScript
111
star
31

san-cli

A CLI Tooling based on San.js for rapid development.
JavaScript
98
star
32

san-mui

A Set of SAN Components that Implement Google's Material Design
JavaScript
95
star
33

ub-ria

RIA base for union business
JavaScript
94
star
34

react-kiss

A simple and stupid react container solution
JavaScript
85
star
35

react-suspense-boundary

A boundary component working with suspense and error
TypeScript
84
star
36

san-xui

A Set of SAN UI Components that widely used on Baidu Cloud Console
JavaScript
81
star
37

gulp-fontmin

Minify font seamlessly
JavaScript
80
star
38

echarts-optimizer

JavaScript
79
star
39

santd

San UI Toolkit for Ant Design
TypeScript
76
star
40

moye

A Simple UI Library for ZX
JavaScript
74
star
41

ecomfe.github.io

https://efe.baidu.com
JavaScript
72
star
42

react-track

A declarative, component based solution to track page views and user events with react & react-router
TypeScript
71
star
43

echarts-graph-modularity

Graph modularity extension for community detection with Apache ECharts
HTML
70
star
44

tempad-dev

Inspect panel on Figma, for everyone.
Vue
67
star
45

diffy-update

Scripts to update object or array with a diff output
JavaScript
54
star
46

gitdiff-parser

A fast and reliable git diff parser.
HTML
53
star
47

learn-graphql-cn

Learn GraphQL 中文翻译
48
star
48

standard-redux-shape

A library to help standardize your redux state shape
JavaScript
47
star
49

htmlcs

HTML Code Style
JavaScript
46
star
50

saber-showcase

使用 saber 创建的 WebApp 示例
JavaScript
41
star
51

smarty4js

a JavaScript template most like smarty, use smarty module in javascript
JavaScript
34
star
52

rebas

Node framework for Saber, base on Express
JavaScript
34
star
53

baidubce-sdk

Baidu Cloud Engine Node.js SDK
JavaScript
28
star
54

node-csshint

Csshint your css code
JavaScript
27
star
55

amd-analyzer

JavaScript
26
star
56

echarts-bmap

HTML
26
star
57

light-dls

Front-end assets and tooling for Baidu Light DLS.
Less
25
star
58

san-loader

San-Loader 是基于 webpack 的工具,允许开发者书写 San 单文件的方式来进行组件开发。
JavaScript
25
star
59

redux-optimistic-thunk

redux-thunk like dispatching with optimistic UI supported
JavaScript
25
star
60

zrender-doc

Document for zrender
JavaScript
22
star
61

grapher.js

JavaScript 3D Plot Library
JavaScript
21
star
62

redux-managed-thunk

A redux-thunk compatible middleware with managed feature to help write more controllable and reusable thunks
JavaScript
20
star
63

efe

EFE guide
20
star
64

mini-event

A simple and dedicated library to provide event related components
JavaScript
18
star
65

veui-theme-blue

a theme for VEUI
Less
18
star
66

esui-family

Online Demo and document of ESUI Family
JavaScript
18
star
67

dls-icons

Icons for Baidu Light DLS.
JavaScript
17
star
68

echarts-gallery-feedback

Official Feedback Repository for ECharts Gallery
16
star
69

edp-webserver

Package for edp webserver.
JavaScript
16
star
70

san-realworld-app

An exemplary real-world application built with San. This is a good example to discover San for beginners.
JavaScript
16
star
71

san-transition

Append transition effects for elements in san components.
JavaScript
16
star
72

node-lesslint

Less lint
JavaScript
15
star
73

ef

ef is a integration framework with er & esui
JavaScript
14
star
74

echarts-builder-web

ECharts online builder
JavaScript
14
star
75

saber-ajax

适用于移动端、promise 风格的 ajax 封装
JavaScript
13
star
76

san-anode-utils

Util Functions for San ANode
JavaScript
13
star
77

promise

A promise respecting ES standard with plenty of handy extensions
JavaScript
12
star
78

saber-env

移动端浏览器环境检测
JavaScript
12
star
79

echarts-dagre

ECharts graph layout extension using dagre.js
JavaScript
12
star
80

aop

Aspect oriented programming utilities
JavaScript
12
star
81

sublime-etpl

An ETPL syntax definition & snippets specifically for Sublime Text.
Python
12
star
82

bat-ria

RIA extensions for Brand Ads
JavaScript
11
star
83

deep-grasp

A toolkit for adopting LLM into your existing app.
TypeScript
11
star
84

ub-ria-ui

UI components for ub ria applications - standardized & implemented
JavaScript
11
star
85

edp-build

Package for edp build.
JavaScript
10
star
86

webpack-auto-cdn-plugin

Webpack plugin to automatically extract dependencies and reference them via CDN
JavaScript
10
star
87

stylelint-config

Standard stylelint config for efe team
JavaScript
10
star
88

saber-promise

适合移动端的 Promise/A+ 实现
JavaScript
10
star
89

rider-ui

基于 rider 的 UI 样式库,用于快速构建移动应用界面
CSS
9
star
90

saber-router

适用于移动端的路由控制,支持 hash, popstate
JavaScript
9
star
91

saber-scroll

为移动端页面提供区域滚动功能
JavaScript
9
star
92

blog

Blog
CSS
9
star
93

html-nest-rule

JavaScript
8
star
94

veui-docs

Documentation website for VEUI.
JavaScript
8
star
95

saber-matchmedia

移动端 matchMedia 支持
JavaScript
8
star
96

eicons

ecom public web font icons
CSS
8
star
97

query-shape

Standard utilities to manage query requests and responses
JavaScript
8
star
98

esf

EFE Style Framework
CSS
8
star
99

saber-dom

一个适用于移动端、静态函数风格的DOM工具库
JavaScript
7
star
100

svg-mixed-loader

Webpack loader resolving svg into url string and multiple component formats.
JavaScript
7
star