SuperAPI AI Directory

chart-image

Data & analytics

View repository

Updated 10-16 00:04

About this skill

Data Chart Generation

Generate high-quality chart images from data, supporting common types such as bar charts, line charts, pie charts, and scatter plots.

Use Cases

  • The user says "turn this data into a chart" or "draw a bar chart"
  • The user provides Excel/CSV data that needs to be visualized
  • Works with excel-analyzer to automatically generate charts after analysis
  • The user says "make a sales trend chart" or "draw a pie chart to see the proportions"

Execution Method

Basic Usage

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# 中文字体支持
plt.rcParams['font.sans-serif'] = ['PingFang SC', 'Microsoft YaHei', 'SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False

fig, ax = plt.subplots(figsize=(10, 6))

# 示例:柱状图
categories = ['一月', '二月', '三月', '四月']
values = [120, 150, 180, 200]
ax.bar(categories, values, color='#4A90D9')

ax.set_title('月度销售额', fontsize=16, fontweight='bold')
ax.set_ylabel('金额(万元)')

plt.tight_layout()
plt.savefig('/tmp/chart.png', dpi=150, bbox_inches='tight')
plt.close()

Supported Chart Types

Type Method Applicable Scenario
Bar Chart ax.bar() Category comparison
Line Chart ax.plot() Trend changes
Pie Chart ax.pie() Proportion analysis
Scatter Plot ax.scatter() Correlation analysis
Horizontal Bar Chart ax.barh() Ranking comparison
Stacked Chart ax.bar(bottom=) Composition analysis

Style Guidelines

  • Default color scheme:#4A90D9(blue),#E85D75(red),#50C878(green),#F5A623(orange)
  • Resolution: 150 DPI (screen viewing) or 300 DPI (printing)
  • Chinese titles and labels must have a Chinese font set
  • Place the legend where it does not obscure the data

Output Guidelines

  • Save the chart as a PNG file to a temporary directory
  • Return the file path for the user to view or embed in a report
  • Automatically select the most suitable chart type (when the user does not specify one)
  • Automatically truncate or aggregate when the data volume is large to avoid a crowded chart