npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prepare-echarts-data

v1.0.0

Published

A utility to prepare data for ECharts visualizations, supporting various aggregation methods.

Readme

prepare-echarts-data

English | 中文说明见下方

prepare-echarts-data is a JavaScript utility for processing input data to generate a format suitable for ECharts. It allows for aggregation of values based on specified dimensions and value fields, supporting various aggregation methods such as sum, average, count, min, and max.

Installation

You can install the package via npm:

npm install prepare-echarts-data

Usage

To use the prepareEChartsDataWithFullAxis function, you need to import it into your project. Here’s an example of how to do that:

import prepareEChartsDataWithFullAxis from 'prepare-echarts-data';

// Sample data
const data = [
  { name: '张三', type: 2, haighe: 170, weight: 30 },
  { name: '张三', type: 1, haighe: 150, weight: 40 },
  { name: '李四', type: 2, haighe: 180, weight: 20 },
  { name: '李四', type: 1, haighe: 200, weight: 60 },
  { name: '张三', type: 2, haighe: 170, weight: 35 }
];

const dimensions = ['name'];
const valueFields = ['weight', 'haighe'];

// Define full X-axis information
const fullXAxis = ['张三', '李四', '王五', '郑六'];

// Generate ECharts data format
const chartData = prepareEChartsDataWithFullAxis(data, dimensions, valueFields, fullXAxis, 'avg', 0);

console.log('chartData:', chartData);
/* {
  chartData: {
    xAxisData: ['张三', '李四', '王五', '郑六'],
      seriesData: {
      weight: [35, 40, 0, 0],
        haighe: [163.33333333333334, 190, 0, 0]
    },
    indexMap: Map(4) { '张三' => 0, '李四' => 1, '王五' => 2, '郑六' => 3 }
  }
} */

API

prepareEChartsDataWithFullAxis(data, dimensions, valueFields, fullXAxis, aggregation, defaultValue)

  • data: An array of objects containing the data to be processed.
  • dimensions: An array of strings representing the dimensions to group by.
  • valueFields: An array of strings representing the fields to aggregate.
  • fullXAxis: An array of strings representing the complete X-axis labels.
  • aggregation: A string indicating the aggregation method ('sum', 'avg', 'count', 'min', 'max').
  • defaultValue: The default value to use for missing data points.

中文说明

prepare-echarts-data 是一个用于处理输入数据并生成适用于 ECharts 格式的 JavaScript 工具。它支持根据指定的维度和数值字段进行聚合,支持多种聚合方式,如求和、平均值、计数、最小值和最大值。

安装

通过 npm 安装:

npm install prepare-echarts-data

用法示例

在项目中引入并使用 prepareEChartsDataWithFullAxis 方法:

import prepareEChartsDataWithFullAxis from 'prepare-echarts-data';

// 示例数据
const data = [
  { name: '张三', type: 2, haighe: 170, weight: 30 },
  { name: '张三', type: 1, haighe: 150, weight: 40 },
  { name: '李四', type: 2, haighe: 180, weight: 20 },
  { name: '李四', type: 1, haighe: 200, weight: 60 },
  { name: '张三', type: 2, haighe: 170, weight: 35 }
];

const dimensions = ['name'];
const valueFields = ['weight', 'haighe'];

// 定义完整的 X 轴标签
const fullXAxis = ['张三', '李四', '王五', '郑六'];

// 生成 ECharts 所需数据格式
const chartData = prepareEChartsDataWithFullAxis(data, dimensions, valueFields, fullXAxis, 'avg', 0);

console.log('chartData:', chartData);
/* {
  chartData: {
    xAxisData: ['张三', '李四', '王五', '郑六'],
      seriesData: {
      weight: [35, 40, 0, 0],
        haighe: [163.33333333333334, 190, 0, 0]
    },
    indexMap: Map(4) { '张三' => 0, '李四' => 1, '王五' => 2, '郑六' => 3 }
  }
} */

API

prepareEChartsDataWithFullAxis(data, dimensions, valueFields, fullXAxis, aggregation, defaultValue)

  • data:待处理的数据对象数组。
  • dimensions:用于分组的维度字段数组。
  • valueFields:需要聚合的数值字段数组。
  • fullXAxis:完整的 X 轴标签数组。
  • aggregation:聚合方式,可选值有 'sum'(求和)、'avg'(平均)、'count'(计数)、'min'(最小值)、'max'(最大值)。
  • defaultValue:缺失数据时的默认值。

License

This project is licensed under the MIT License. See the LICENSE file for details.