ecomfe / echarts-stat

Statistics tool for Apache ECharts
593 stars 309 forks source link

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

Parameter
Return Value (only for standalone usage)

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

Parameter
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:

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

Parameters
Return Value (only for standalone usage)

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
Return Value

ecStat.statistics.sampleVariance()

Syntax
var varianceValue = ecStat.statistics.sampleVariance(dataList);
Parameter
Return Value

ecStat.statistics.quantile()

Syntax
var quantileValue = ecStat.statistics.quantile(dataList, p);
Parameter
Return Value

ecStat.statistics.max()

Syntax
var maxValue = ecStat.statistics.max(dataList);
Parameter
Return Value

ecStat.statistics.min()

Syntax
var minValue = ecStat.statistics.min(dataList);
Parameter
Return Value

ecStat.statistics.mean()

Syntax
var meanValue = ecStat.statistics.mean(dataList);
Parameter
Return Value

ecStat.statistics.median()

Syntax
var medianValue = ecStat.statistics.median(dataList);
Parameter
Return Value

ecStat.statistics.sum()

Syntax
var sumValue = ecStat.statistics.sum(dataList);
Parameter
Return Value

Notice

The Apache Software Foundation Apache ECharts, ECharts, Apache, the Apache feather, and the Apache ECharts project logo are either registered trademarks or trademarks of the Apache Software Foundation.