Smart Charts
An intelligent chart-generation and data-analysis skill. It reads user-supplied data files, understands their structure and semantics, recommends the most appropriate chart types, generates interactive HTML reports powered by ECharts, and (when a saved report template exists) fills the template automatically.
Installation / 安装
CODEBLOCK0
Dependencies / 依赖
| Package | Required | Description |
|---|
| INLINECODE0 | ✅ Yes | Data parsing (CSV, Excel, JSON) |
| INLINECODE1 |
✅ Yes | Numerical computations |
|
openpyxl>=3.0.0 | ✅ Yes | Excel file engine |
|
PyPDF2>=3.0.0 | Optional | PDF template extraction |
|
python-docx>=0.8.0 | Optional | Word template processing |
ECharts is loaded via CDN (jsdelivr) — no local installation required.
Activation Triggers
Load and run this skill when any of the following conditions are met:
- - The user mentions: "analyze data", "generate chart", "data visualization", "chart", "visualization"
/ 用户提到:「分析数据」「生成图表」「数据可视化」「chart」「visualization」
- - The user provides a data file (CSV / Excel / JSON / TXT) and asks for analysis or visualization
/ 用户上传或提供数据文件并要求分析或可视化
- - The user asks to generate charts or a report from tabular data
/ 用户要求从表格数据生成图表或报告
User Guidance
When no data file is provided
Prompt the user:
Please upload the data file(s) you want to analyze. Supported formats:
- - CSV (.csv / .tsv / .txt)
- Excel (.xlsx / .xls)
- JSON (.json)
You can drag files directly into the chat box. Multiple files are supported.
/ 请上传需要分析的数据文件。支持 CSV / Excel / JSON 格式,可同时上传多个文件。
When data files are provided
Step 1 — Parse and display a unified summary:
Files loaded: 3
| File | Rows | Cols | Key Fields |
|---|
| eastsales.csv | 120 | 8 | date, revenue, profit… |
| southsales.csv |
98 | 8 | date, revenue, profit… |
| products.xlsx | 45 | 5 | name, category, price… |
Step 2 — Infer file relationships and recommend an analysis strategy:
| Situation | Recommendation |
|---|
| Same schema across files | Merge and compare |
| Shared common column(s) |
Join on the common key |
| Unrelated schemas | Analyze each file separately |
| Single file | Analyze directly |
Step 3 — Execute after user confirmation.
Error handling
| Error | User message |
|---|
| File not found | "File not found. Please verify the path or drag the file into the chat." |
| Unsupported format |
"Unsupported file format. Please convert to CSV, Excel, or JSON and retry." |
| File > 100 MB | "File too large. Consider filtering or splitting the data before uploading." |
| Empty file | "The file appears to be empty. Please check that it contains valid data." |
| Encoding error | "Encoding issue detected. Try re-saving the file as CSV (UTF-8) and retry." |
| Cannot auto-merge | "Schemas differ too much to merge automatically. Analyze separately, or specify a join key." |
Execution Workflow
CODEBLOCK1
Configuration
CODEBLOCK2
Important: Never hard-code absolute paths. All paths must be provided by the user or resolved dynamically from the working directory.
Data Parsing — CLI Reference
Usage / 调用方式
CODEBLOCK3
Merge behavior:
| Condition | Result |
|---|
| Identical column names | Vertical concat; a source_file column is added |
| Shared columns exist |
Horizontal join on shared key |
| No common structure | Error — advise analyzing separately |
Supported formats
| Format | Extensions | Notes |
|---|
| CSV | .csv, .tsv | Auto-detects delimiter and encoding (UTF-8 / GBK / GB2312) |
| Plain text |
.txt | Auto-detects delimiter (comma / tab / semicolon / pipe) |
| Excel | .xlsx, .xls | Reads first non-empty sheet |
| JSON | .json | Supports array format and nested objects |
Chart Generation — CLI Reference
Usage / 调用方式
CODEBLOCK4
Parameters
| Parameter | Required | Description |
|---|
| INLINECODE7 | Yes | Path to the data file |
| INLINECODE8 |
Yes | Chart type identifier (see table below) |
|
--title | No | Chart title; default: "Data Chart" |
|
--x-axis | No | X-axis field; auto-detected if omitted |
|
--y-axis | No | Y-axis field(s), space-separated; defaults to first 5 numeric columns |
|
--output-dir | No | Output directory; default:
./smart_charts_output |
Supported chart types
| ID | Name | Best For |
|---|
| INLINECODE14 | Line chart | Time-series trends, continuous data |
| INLINECODE15 |
Bar chart | Category comparison, ranked discrete data |
|
pie | Pie chart | Composition, share distribution |
|
scatter | Scatter plot | Correlation, density distribution |
|
area | Area chart | Cumulative change, emphasized trend |
|
radar | Radar chart | Multi-dimension comparison, scoring |
|
heatmap | Heatmap | Density, cross-tabulation analysis |
|
treemap | Treemap | Hierarchical proportion, attribution |
|
graph | Network graph | Entity relationships, network topology |
|
boxplot | Box plot | Distribution, outlier detection |
|
waterfall | Waterfall chart | Incremental change, contribution breakdown |
|
gauge | Gauge chart | KPI progress, target tracking |
|
sankey | Sankey diagram | Flow transfer, conversion path |
|
funnel | Funnel chart | Conversion rate, stage analysis |
|
sunburst | Sunburst chart | Multi-level composition, nested proportion |
|
wordcloud | Word cloud | Frequency distribution, keyword visualization |
Report Templates
Users can store custom report templates under the templates_dir directory.
Directory structure
CODEBLOCK5
meta.json schema
CODEBLOCK6
LLM-driven template matching
Core principle: template matching is performed by the LLM, not by hard-coded algorithms.
Step 1 — Discover templates and collect metadata
CODEBLOCK7
Step 2 — LLM analyzes the user task
CODEBLOCK8
Step 3 — LLM selects the best-matching template
CODEBLOCK9
Step 4 — Load template and fill with data insights
CODEBLOCK10
Fallback behavior (no match)
| Scenario | Behavior |
|---|
| No suitable template | LLM generates report freely |
| Partial match |
LLM uses template structure as reference, generates the rest |
| Empty template library | LLM creates a professional report from scratch |
Template variable syntax (auto-detected)
| Format | Example |
|---|
| Single braces | INLINECODE31 |
| Double braces |
{{variable_name}} |
| Square brackets |
[variable_name] |
| Percent signs |
%variable_name% |
Template Management
Supported template formats
| Format | Extension | Processing |
|---|
| Markdown | .md, .markdown | Native support |
| Word |
.docx | Extracts text and preserves formatting |
| PDF | .pdf | Extracts text and structure |
| Plain text | .txt | Simple template parsing |
Operations / 操作指令
Upload / Save a template
- - Triggers:
upload template, add template, INLINECODE37
/ 触发词:
上传模板、
添加模板、 INLINECODE40
CODEBLOCK11
View template library
- - Triggers:
my templates, template list, INLINECODE43
/ 触发词:
我的模板、
模板列表、 INLINECODE46
CODEBLOCK12
Auto-matching (seamless)
CODEBLOCK13
Template management error handling
| Error | User message | Suggested action |
|---|
| Unsupported format | "Supported formats: PDF, Word, Markdown." | Convert and retry |
| Template already exists |
"Template 'Sales Report' already exists." | Overwrite, rename, or cancel |
| No match found | "No exact template match found." | Use generic template or create new |
| Missing variables | "Data missing: revenue, profit." | Check data file or use defaults |
Key Principles
- 1. Multi-file first — Users often upload multiple files. Guide proactively; handle batches gracefully.
- Confirm before executing — Always show a data summary and confirm understanding before recommending analysis direction.
- LLM chooses chart types — Recommend based on data semantics; never hard-code mapping rules.
- Template-first report generation — Use a saved template when a good match exists; fall back to free-form only when necessary.
- Dynamic path resolution — Absolute paths must never be hard-coded; resolve all paths at runtime.
- Immediate result presentation — Charts via
preview_url; Markdown reports via open_result_view.
Smart Charts
一个智能图表生成与数据分析技能。它能读取用户提供的数据文件,理解其结构与语义,推荐最合适的图表类型,生成由 ECharts 驱动的交互式 HTML 报告,并在存在已保存的报告模板时自动填充模板。
安装
bash
pip install -r requirements.txt
依赖
| 包 | 必需 | 描述 |
|---|
| pandas>=1.5.0 | ✅ 是 | 数据解析(CSV、Excel、JSON) |
| numpy>=1.21.0 |
✅ 是 | 数值计算 |
| openpyxl>=3.0.0 | ✅ 是 | Excel 文件引擎 |
| PyPDF2>=3.0.0 | 可选 | PDF 模板提取 |
| python-docx>=0.8.0 | 可选 | Word 模板处理 |
ECharts 通过 CDN(jsdelivr)加载——无需本地安装。
激活触发条件
当满足以下任一条件时,加载并运行此技能:
- - 用户提到:「分析数据」「生成图表」「数据可视化」「chart」「visualization」
/ 用户提到:「分析数据」「生成图表」「数据可视化」「chart」「visualization」
- - 用户提供数据文件(CSV / Excel / JSON / TXT)并要求分析或可视化
/ 用户上传或提供数据文件并要求分析或可视化
/ 用户要求从表格数据生成图表或报告
用户引导
未提供数据文件时
提示用户:
请上传您要分析的数据文件。支持的格式:
- - CSV(.csv / .tsv / .txt)
- Excel(.xlsx / .xls)
- JSON(.json)
您可以直接将文件拖入聊天框。支持多个文件。
/ 请上传需要分析的数据文件。支持 CSV / Excel / JSON 格式,可同时上传多个文件。
已提供数据文件时
第 1 步——解析并显示统一摘要:
已加载文件:3
| 文件 | 行数 | 列数 | 关键字段 |
|---|
| eastsales.csv | 120 | 8 | date, revenue, profit… |
| southsales.csv |
98 | 8 | date, revenue, profit… |
| products.xlsx | 45 | 5 | name, category, price… |
第 2 步——推断文件关系并推荐分析策略:
基于共同键进行连接 |
| 结构无关 | 分别分析每个文件 |
| 单个文件 | 直接分析 |
第 3 步——用户确认后执行。
错误处理
| 错误 | 用户消息 |
|---|
| 文件未找到 | 文件未找到。请检查路径或将文件拖入聊天框。 |
| 不支持的格式 |
不支持的格式。请转换为 CSV、Excel 或 JSON 后重试。 |
| 文件 > 100 MB | 文件过大。请考虑在上传前过滤或拆分数据。 |
| 空文件 | 文件似乎为空。请检查是否包含有效数据。 |
| 编码错误 | 检测到编码问题。请尝试将文件另存为 CSV(UTF-8)后重试。 |
| 无法自动合并 | 结构差异过大,无法自动合并。请分别分析,或指定连接键。 |
执行流程
- 1. 获取数据文件
└─ 用户直接上传文件(主要方式)
└─ 或用户提供文件路径
- 2. 解析数据
└─ 对所有文件调用 data_parser.py
└─ 单个文件 → 直接解析
└─ 多个文件 → 分别解析,评估合并可行性
- 3. 确认与推荐
└─ 显示所有文件的摘要表格
└─ 推荐:合并 / 分别分析 / 连接
└─ 根据数据特征推荐图表类型
- 4. 生成图表
└─ 调用 chart_generator.py → 生成 ECharts HTML
└─ 合并数据 → 跨组对比图表
└─ 分别数据 → 每个文件独立图表
└─ 图表类型由 LLM 根据数据形态选择
- 5. 检查报告模板
└─ 扫描技能库下的 templates/ 子目录
└─ 读取每个 meta.json;由 LLM 判断相关性
└─ 无匹配模板 → 跳转到自由生成
- 6. 生成分析报告
└─ 找到匹配模板 → 用数据洞察填充 template.md
└─ 无匹配模板 → LLM 自由生成报告
- 7. 呈现结果
└─ 交互式图表:使用 preview_url(HTML)
└─ Markdown 报告:使用 open
resultview
配置
yaml
outputdir: 输出目录(可选;默认:./smartcharts_output)
templates_dir: 报告模板目录(可选;默认:./templates)
重要: 切勿硬编码绝对路径。所有路径必须由用户提供或从工作目录动态解析。
数据解析——CLI 参考
调用方式
bash
单文件
python {skill
base}/core/dataparser.py
[--summary]
多文件
python {skillbase}/core/dataparser.py ... [--summary]
多文件自动合并
python {skillbase}/core/dataparser.py ... [--merge] [--summary]
合并行为:
| 条件 | 结果 |
|---|
| 列名完全相同 | 纵向拼接;添加 source_file 列 |
| 存在共同列 |
基于共同键横向连接 |
| 无共同结构 | 报错——建议分别分析 |
支持的格式
| 格式 | 扩展名 | 备注 |
|---|
| CSV | .csv, .tsv | 自动检测分隔符和编码(UTF-8 / GBK / GB2312) |
| 纯文本 |
.txt | 自动检测分隔符(逗号 / 制表符 / 分号 / 竖线) |
| Excel | .xlsx, .xls | 读取第一个非空工作表 |
| JSON | .json | 支持数组格式和嵌套对象 |
图表生成——CLI 参考
调用方式
bash
python {skillbase}/core/chartgenerator.py \
path> type> \
--title 图表标题 \
--x-axis date \
--y-axis revenue profit \
--output-dir ./output
参数
| 参数 | 必需 | 描述 |
|---|
| filepath | 是 | 数据文件路径 |
| charttype |
是 | 图表类型标识符(见下表) |
| --title | 否 | 图表标题;默认:Data Chart |
| --x-axis | 否 | X 轴字段;省略时自动检测 |
| --y-axis | 否 | Y 轴字段,空格分隔;默认为前 5 个数值列 |
| --output-dir | 否 | 输出目录;默认:./smartchartsoutput |
支持的图表类型
| ID | 名称 | 最佳用途 |
|---|
| line | 折线图 | 时间序列趋势、连续数据 |
| bar |
柱状图 | 类别对比、排序离散数据 |
| pie | 饼图 | 构成、份额分布 |
| scatter | 散点图 | 相关性、密度分布 |
| area | 面积图 | 累积变化、强调趋势 |
| radar | 雷达图 | 多维度对比、评分 |
| heatmap | 热力图 | 密度、交叉分析 |
| treemap | 矩形树图 | 层级比例、归属分析 |
| graph | 关系图 | 实体关系、网络拓扑 |
| boxplot | 箱线图 | 分布、异常值检测 |
| waterfall | 瀑布图 | 增量变化、贡献分解 |
| gauge | 仪表盘 | KPI 进度、目标追踪 |
| sankey | 桑基图 | 流量转移、转化路径 |
| funnel | 漏斗图 | 转化率、阶段分析 |
| sunburst | 旭日图 |