Skip to content
Back to skills

Devlab Web Echarts Usage

ASecurity

ECharts 在 Astro/前端项目中的完整集成指南,包含 tree-shaking、IntersectionObserver 按需加载、自定义系列集成、拓扑图实现、雷达图配置、Astro Islands 数据传递、调试经验。

  • 21 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 1, 2026
ai-agentstypescriptreactvue

Works with

  • cli

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned September 1, 2026

npx -y skills add seed-forge/harness-ai-kit --skill devlab-web-echarts-usage --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Devlab Web Echarts Usage?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Devlab Web Echarts Usage
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/seed-forge-devlab-web-echarts-usage/badge)](https://www.skillsdirectory.com/skills/seed-forge-devlab-web-echarts-usage)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: devlab-web-echarts-usage
description: ECharts 在 Astro/前端项目中的完整集成指南,包含 tree-shaking、IntersectionObserver 按需加载、自定义系列集成、拓扑图实现、雷达图配置、Astro Islands 数据传递、调试经验。
---

# devlab-web-echarts-usage

## 用途

ECharts 在 Astro/前端项目中的完整集成指南,包含 tree-shaking、IntersectionObserver 按需加载、自定义系列集成、拓扑图实现、雷达图配置、调试经验。

**适用场景**:
- 在 Astro/React/Vue 项目中引入 ECharts 图表
- 需要 tree-shaking 以避免全量 300KB 加载
- 需要 IntersectionObserver 按需加载(视口进入才加载)
- 实现 force-directed 拓扑图、雷达图、散点图等
- 处理 ECharts 在 Astro Islands 模式下的数据传递

## 核心概念

### Tree-Shaking 导入

ECharts 必须使用 tree-shaking 导入,否则会加载全量 ~300KB:

```typescript
// ✅ 正确:只导入需要的子模块
import * as echarts from "echarts/core";
import { RadarChart, ScatterChart, EffectScatterChart } from "echarts/charts";
import { TooltipComponent, LegendComponent, GridComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";

echarts.use([RadarChart, ScatterChart, EffectScatterChart, TooltipComponent, LegendComponent, GridComponent, CanvasRenderer]);

// ❌ 错误:全量导入
import * as echarts from "echarts";
```

### Astro Islands 数据传递

Astro 组件通过 `data-*` 属性传递数据到客户端脚本:

```astro
<div class="chart" data-scores={JSON.stringify(scores)}></div>

<script>
const container = document.querySelector('.chart');
const scores = JSON.parse(container.dataset.scores);
// 使用 scores 初始化 ECharts...
</script>
```

### IntersectionObserver 按需加载

图表不在首屏时,延迟加载以减少首屏 JS payload:

```typescript
export function observeChart(container, onReady) {
  const observer = new IntersectionObserver((entries) => {
    for (const entry of entries) {
      if (entry.isIntersecting) {
        observer.unobserve(container);
        const chart = echarts.init(container);
        if (chart) onReady(chart);
      }
    }
  }, { rootMargin: "200px" });
  observer.observe(container);
}
```

## 实现流程

1. 确定目标图表类型(雷达图/拓扑图/折线图等)
2. 配置 tree-shaking imports(echarts/charts + echarts/components)
3. 设置 IntersectionObserver 按需加载
4. 实现图表渲染 + 响应式 resize
5. 处理 Astro Islands 集成(客户端脚本 + 数据传递)
6. 处理 prefers-reduced-motion 降级

## 推荐输出格式

执行完毕后输出极简回执:**状态**(✅ 成功 / ⚠️ 部分成功 / ❌ 失败)+ **关键结果**(1-2 行,如操作对象、产出位置、下一步)。无需强制套用大表格。


## 约束

- **MUST** 使用 ECharts tree-shaking(非全量 300KB)
- **MUST** IntersectionObserver 按需加载
- **MUST** 处理 prefers-reduced-motion 降级(显示静态数据或简化图表)
- **MUST NOT** 在 SSR 阶段执行 ECharts 初始化(仅 client-side)

## 参考

- [ECharts 官方文档](https://echarts.apache.org/)
- [ECharts Tree Shaking](https://echarts.apache.org/handbook/en/basics/import/)
- [踩坑经验](references/REFERENCE-PITFALLS.md)

参考文档:
- references/REFERENCE-README.md

Files in this skill

  • CHANGELOG.md967 B
  • README.md154 B
  • SKILL.md3.3 KB
  • USAGE.md423 B
  • references/REFERENCE-PITFALLS.md2.9 KB
  • references/REFERENCE-README.md91 B
  • skill.json1.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.