| name | chart-generator |
| description | Data visualization chart generator. Use when user needs to create charts from data for reports, presentations, or documents. Supports bar, line, pie, scatter, radar charts with PNG/SVG output. 数据可视化、图表生成、数据报告。 |
| version | 1.0.2 |
| license | MIT-0 |
| metadata | {"openclaw":{"emoji":"📊","requires":{"bins":["python3"]}}} |
| dependencies | pip install matplotlib pandas openpyxl python-docx pillow |
Chart Generator
Professional data visualization chart generator for reports, presentations, and documents.
Features
- 📊 Multiple Chart Types: Bar, line, pie, scatter, radar, area, stacked
- 📁 Multiple Data Sources: CSV, Excel, JSON, manual, web, document extraction
- 🎨 Professional Styling: Clean, publication-ready charts with custom options
- 📐 Flexible Output: PNG, SVG, PDF, Word, Excel, Markdown, HTML
- 🔗 Embed Support: Direct embedding into documents
- 🌍 Multi-Language: Chinese, English, Japanese, Korean (no encoding issues)
- ✅ Cross-Platform: Windows, macOS, Linux
Supported Chart Types
| Type | Use Case | Best For |
|---|
| Bar Chart | Compare values | Sales, rankings |
| Line Chart | Show trends | Time series, growth |
| Pie Chart | Show proportions | Market share, composition |
| Scatter Plot | Show correlation | Data relationships |
| Radar Chart | Multi-dimension | Performance comparison |
| Area Chart | Cumulative values | Stacked data |
| Stacked Bar | Composition | Multi-category breakdown |
Trigger Conditions
- "帮我画图" / "Create a chart"
- "生成柱状图" / "Generate bar chart"
- "数据可视化" / "Data visualization"
- "做一个趋势图" / "Make a trend chart"
- "图表分析" / "Chart analysis"
- "chart-generator"
Step 1: Understand Requirements
请提供以下信息:
图表类型:(柱状图/折线图/饼图/散点图/雷达图)
数据来源:(手动输入/CSV/Excel/JSON)
数据内容:
标题:
X轴标签:
Y轴标签:
输出格式:(PNG/SVG)
颜色要求:(默认/自定义)
Step 2: Generate Chart
Python Script Template
python3 << 'PYEOF'
import os
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
import numpy as np
from matplotlib import font_manager
plt.rcParams['font.sans-serif'] = ['Noto Sans SC', 'SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
class ChartGenerator:
def __init__(self):
self.fig = None
self.ax = None
def create_bar_chart(self, labels, values, title='',
xlabel='', ylabel='',
color='#3182ce', output_path=None):
"""Create bar chart"""
self.fig, self.ax = plt.subplots(figsize=(10, 6))
bars = self.ax.bar(labels, values, color=color, edgecolor='white', linewidth=0.5)
for bar in bars:
height = bar.get_height()
self.ax.text(bar.get_x() + bar.get_width()/, height,
,
ha=, va=, fontsize=)
.ax.set_title(title, fontsize=, fontweight=, pad=)
.ax.set_xlabel(xlabel, fontsize=)
.ax.set_ylabel(ylabel, fontsize=)
.ax.spines[].set_visible()
.ax.spines[].set_visible()
.ax.grid(axis=, alpha=)
plt.tight_layout()
output_path:
.fig.savefig(output_path, dpi=, bbox_inches=)
plt.close()
output_path
.fig
():
.fig, .ax = plt.subplots(figsize=(, ))
colors :
colors = [, , , , ]
i, y_data (y_data_list):
color = colors[i % (colors)]
label = labels[i] labels i < (labels)
.ax.plot(x_data, y_data, marker=, linewidth=,
color=color, label=label, markersize=)
.ax.set_title(title, fontsize=, fontweight=, pad=)
.ax.set_xlabel(xlabel, fontsize=)
.ax.set_ylabel(ylabel, fontsize=)
labels:
.ax.legend(loc=, framealpha=)
.ax.spines[].set_visible()
.ax.spines[].set_visible()
.ax.grid(alpha=)
plt.tight_layout()
output_path:
.fig.savefig(output_path, dpi=, bbox_inches=)
plt.close()
output_path
.fig
():
.fig, .ax = plt.subplots(figsize=(, ))
colors :
colors = [, , , , ,
, , ]
wedges, texts, autotexts = .ax.pie(
values, labels=labels, colors=colors[:(values)],
autopct=, startangle=,
textprops={: }
)
autotext autotexts:
autotext.set_color()
autotext.set_fontweight()
.ax.set_title(title, fontsize=, fontweight=, pad=)
plt.tight_layout()
output_path:
.fig.savefig(output_path, dpi=, bbox_inches=)
plt.close()
output_path
.fig
():
.fig, .ax = plt.subplots(figsize=(, ))
.ax.scatter(x_data, y_data, c=color, alpha=, s=)
z = np.polyfit(x_data, y_data, )
p = np.poly1d(z)
.ax.plot(x_data, p(x_data), , color=, alpha=, label=)
.ax.set_title(title, fontsize=, fontweight=, pad=)
.ax.set_xlabel(xlabel, fontsize=)
.ax.set_ylabel(ylabel, fontsize=)
.ax.legend()
.ax.spines[].set_visible()
.ax.spines[].set_visible()
.ax.grid(alpha=)
plt.tight_layout()
output_path:
.fig.savefig(output_path, dpi=, bbox_inches=)
plt.close()
output_path
.fig
():
.fig, .ax = plt.subplots(figsize=(, ))
x = np.arange((labels))
width = / (data_dict)
colors = [, , , , ]
i, (name, values) (data_dict.items()):
offset = (i - (data_dict)/ + ) * width
bars = .ax.bar(x + offset, values, width, label=name,
color=colors[i % (colors)], edgecolor=)
.ax.set_title(title, fontsize=, fontweight=, pad=)
.ax.set_xlabel(xlabel, fontsize=)
.ax.set_ylabel(ylabel, fontsize=)
.ax.set_xticks(x)
.ax.set_xticklabels(labels)
.ax.legend()
.ax.spines[].set_visible()
.ax.spines[].set_visible()
.ax.grid(axis=, alpha=)
plt.tight_layout()
output_path:
.fig.savefig(output_path, dpi=, bbox_inches=)
plt.close()
output_path
.fig
():
df = pd.read_csv(csv_path)
x_col :
x_col = df.columns[]
y_cols :
y_cols = [col col df.columns col != x_col]
{
: df[x_col].tolist(),
: {col: df[col].tolist() col y_cols},
: df
}
():
df = pd.read_excel(excel_path, sheet_name=sheet_name)
x_col :
x_col = df.columns[]
y_cols :
y_cols = [col col df.columns col != x_col]
{
: df[x_col].tolist(),
: {col: df[col].tolist() col y_cols},
: df
}
():
json
(json_path, , encoding=) f:
data = json.load(f)
data
():
glob
all_data = []
file_path glob.glob(os.path.join(dir_path, file_pattern)):
file_path.endswith():
df = pd.read_csv(file_path)
file_path.endswith():
df = pd.read_excel(file_path)
:
df[] = os.path.basename(file_path)
all_data.append(df)
all_data:
pd.concat(all_data, ignore_index=)
pd.DataFrame()
():
re
patterns = [
,
,
]
data = {}
pattern patterns:
matches = re.findall(pattern, text)
matches:
() == :
key, value =
:
data[key] = (value)
ValueError:
data
():
.fig:
.fig.savefig(output_path, dpi=dpi, bbox_inches=,
facecolor=, edgecolor=)
output_path
():
.fig:
.fig.savefig(output_path, =, bbox_inches=,
facecolor=, edgecolor=)
output_path
():
.fig:
.fig.savefig(output_path, =, bbox_inches=,
facecolor=, edgecolor=)
output_path
():
io
base64
.fig:
buffer = io.BytesIO()
.fig.savefig(buffer, =, bbox_inches=,
facecolor=, edgecolor=)
buffer.seek()
img_str = base64.b64encode(buffer.read()).decode()
():
base64_img = .save_to_base64()
md =
title:
md +=
md +=
caption:
md +=
md
():
base64_img = .save_to_base64()
html =
html
():
docx Document
docx.shared Inches
doc = Document()
title:
doc.add_heading(title, level=)
temp_img = output_path.replace(, )
.save_to_png(temp_img)
doc.add_picture(temp_img, width=Inches())
caption:
last_para = doc.paragraphs[-]
last_para.alignment =
doc.save(output_path)
os.path.exists(temp_img):
os.remove(temp_img)
output_path
generator = ChartGenerator()
output_dir = os.environ.get(, os.getcwd())
labels = [, , , ]
values = [, , , ]
generator.create_bar_chart(
labels, values,
title=,
xlabel=,
ylabel=,
output_path=os.path.join(output_dir, )
)
months = [, , , , , ]
product_a = [, , , , , ]
product_b = [, , , , , ]
generator.create_line_chart(
months, [product_a, product_b],
labels=[, ],
title=,
xlabel=,
ylabel=,
output_path=os.path.join(output_dir, )
)
pie_labels = [, , , ]
pie_values = [, , , ]
generator.create_pie_chart(
pie_labels, pie_values,
title=,
output_path=os.path.join(output_dir, )
)
()
PYEOF
Data Sources (数据来源)
From CSV
generator = ChartGenerator()
data = generator.load_from_csv('data.csv', x_col='Month', y_cols=['Sales', 'Profit'])
generator.create_line_chart(
data['x'],
[data['y']['Sales'], data['y']['Profit']],
labels=['Sales', 'Profit'],
title='Monthly Performance'
)
From Excel
data = generator.load_from_excel('report.xlsx', sheet_name='Sheet1')
Manual Input
labels = ['A', 'B', 'C', 'D']
values = [100, 200, 150, 300]
generator.create_bar_chart(labels, values)
Styling Options (样式选项)
Colors
color='#3182ce'
colors=['#3182ce', '#48bb78', '#ed8936', '#e53e3e']
Size
figsize=(10, 6)
figsize=(16, 9)
figsize=(8, 8)
Security Notes
- ✅ No network calls or external endpoints
- ✅ No credentials or API keys required
- ✅ Local file processing only
- ✅ Open source dependencies (matplotlib, pandas)
- ✅ No data uploaded to external servers
Notes
- Uses matplotlib for chart generation
- Supports CSV, Excel, and manual data input
- Output formats: PNG, SVG, PDF
- Chinese font support with Noto Sans SC
- Cross-platform compatible