Community程式設計與開發github.com

部落格圖表

產生相容於深色模式的內嵌 SVG 圖表,用於部落格文章中。由 `blog-write` 和 `blog-rewrite` 在識別出適合繪製圖表的資料時內部呼叫。

部落格圖表 是什麼?

此技能專為在 AI 輔助寫作流程(例如搭配 Claude Code 或 Cursor 等工具)中,於部落格文章內自動生成 SVG 圖表而設計。它根據資料模式(如趨勢、比較、佔比)選擇最合適的圖表類型(如長條圖、折線圖、圓環圖),並嚴格遵守深色/淺色模式相容的樣式規則——所有文字皆使用 `currentColor`,背景為透明。其核心優勢在於確保無障礙性(提供 `role="img"`、`aria-label`、`title` 與 `desc` 元素)與視覺一致性。支援 HTML 與 MDX 兩種輸出格式,在 JSX 中會自動將屬性轉換為 camelCase。這並非獨立供使用者呼叫的命令,而是被 `blog-write` 與 `blog-rewrite` 等較高層級的寫作技能觸發,非常適合需要頻繁產生資料視覺化內容的部落格寫作工作流程。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AgriciDaniel/claude-blog/tree/main/skills/blog-chart

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Blog Chart -- 內建 SVG 資料視覺化

為部落格文章產生相容於深色模式的內嵌 SVG 圖表。當 blog-write 和 blog-rewrite 識別出適合繪製圖表的資料時,會由內部呼叫。這不是一個獨立的、供使用者直接使用的命令。

樣式來源依據: references/visual-media.md

輸入格式

文章撰寫者或研究員傳入一個圖表請求:

Chart Request:
- Type: horizontal bar
- Title: "AI Citation Sources by Platform"
- Data: ChatGPT 43.8%, Perplexity 6.6%, Google AI Overviews 2.2%, Reddit 7.15%
- Source: Ahrefs, December 2025
- Platform: mdx (or html)

圖表類型選擇

根據資料模式選擇。務必多樣化——同一篇文章中不得重複使用同一種圖表類型。

資料模式最佳圖表類型
前/後比較分組長條圖 (Grouped bar chart)
排名因素 / 相關性棒棒糖圖 (Lollipop chart)
整體部分 / 市佔率圓環圖 (Donut chart)
隨時間趨勢折線圖 (Line chart)
百分比改善水平長條圖 (Horizontal bar chart)
分佈 / 範圍面積圖 (Area chart)
多維度評分雷達圖 (Radar chart)

樣式規則(不可協商)

所有圖表必須在深色和淺色背景上都能正常顯示:

Text elements:     fill="currentColor"
Grid lines:        stroke="currentColor" opacity="0.08"
Axis lines:        stroke="currentColor" opacity="0.3"
Background:        transparent (no fill on root SVG)
Subtitle text:     fill="currentColor" opacity="0.45"
Source text:        fill="currentColor" opacity="0.35"
Label text:        fill="currentColor" opacity="0.8"

色板

顏色Hex用途
橙色#f97316主要 / 最高值
天藍色#38bdf8次要 / 比較用
紫色#a78bfa第三層級 / 特殊類別
綠色#22c55e第四層級 / 正向指標

對於彩色元素內部的文字:fill="white" 搭配 fontWeight="800"。

標準 SVG 外殼 (HTML)

<svg
  viewBox="0 0 560 380"
  style="max-width: 100%; height: auto; font-family: 'Inter', system-ui, sans-serif"
  role="img"
  aria-label="Chart description with key data point"
>
  <title>Chart Title</title>
  <desc>Description for screen readers with all key data points and source</desc>

  <!-- Chart content -->

  <text x="280" y="372" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.35">
    Source: Source Name (Year)
  </text>
</svg>

JSX/MDX 外殼 (camelCase 屬性)

<svg
  viewBox="0 0 560 380"
  style={{maxWidth: '100%', height: 'auto', fontFamily: "'Inter', system-ui, sans-serif"}}
  role="img"
  aria-label="Chart description"
>
  <title>Chart Title</title>
  <desc>Description for screen readers</desc>

  {/* Chart content */}

  <text x="280" y="372" textAnchor="middle" fontSize="10" fill="currentColor" opacity="0.35">
    Source: Source Name (Year)
  </text>
</svg>

JSX 屬性轉換 (MDX 必須)

HTMLJSX
stroke-widthstrokeWidth
stroke-dasharraystrokeDasharray
stroke-linecapstrokeLinecap
text-anchortextAnchor
font-sizefontSize
font-weightfontWeight
font-familyfontFamily
classclassName
style="..."style={{...}}

圖表類型建構

水平長條圖

最適合:百分比改善、單一指標比較。

  1. 定義圖表區域:x=80, y=40, width=440, height=280
  2. 計算長條高度:chartHeight / dataCount - gap (gap=8)
  3. 計算長條寬度:(value / maxValue) * chartWidth
  4. 定位長條:y = chartY + index * (barHeight + gap)
  5. 左側標籤(右對齊,x=75):類別名稱
  6. 長條末端數值標籤:百分比或數字
  7. 底部中央來源文字

分組長條圖

最適合:前/後比較、A vs B 比較。

  1. 沿 Y 軸定義組別,每組內有數個長條
  2. 使用 2 種顏色(主要 + 次要)代表兩個系列
  3. 頂部加入圖例:顏色方塊 + 系列標籤
  4. 組間間距 > 組內間距

圓環圖

最適合:整體部分、市佔率。

  1. 中心點:cx=280, cy=180, 外半徑=140, 內半徑=80
  2. 使用累計角度計算弧形區段
  3. 每個區段:<path d="M... A... L... A... Z" fill="color" />
  4. 中心文字:總計或關鍵標籤
  5. 圖表下方圖例:顏色方塊 + 標籤 + 數值

折線圖

最適合:隨時間趨勢。

  1. X 軸:時間區段,等距分佈
  2. Y 軸:數值範圍,包含 4-5 條格線
  3. 繪製格線:stroke="currentColor" opacity="0.08"
  4. 標示資料點:<circle cx=... cy=... r="4" fill="color" />
  5. 連接點:<polyline points="..." fill="none" stroke="color" strokeWidth="2" />
  6. 可選:線下方區域填色,opacity="0.1"

棒棒糖圖

最適合:排名因素、相關性。

  1. 水平方向(類似長條圖但使用圓形)
  2. 從軸線到資料點的細線:stroke="currentColor" opacity="0.15" strokeWidth="1"
  3. 資料點的圓形:r="6" 搭配填滿顏色
  4. 圓形旁的數值標籤
  5. Y 軸上的類別(左對齊)

面積圖

最適合:分佈、累積資料。

  1. 與折線圖相同,但線下方區域有填色
  2. 區域填色:<path d="M... L... L... Z" fill="color" opacity="0.15" />
  3. 上方線條:stroke="color" strokeWidth="2" fill="none"
  4. 格線位於區域後方

雷達圖

最適合:多維度評分(5-7 個軸線)。

  1. 中心點:cx=280, cy=190
  2. 繪製同心多邊形作為網格(3-4 層級)
  3. 計算等角度間隔的軸線端點
  4. 在每個軸線上,根據數值比例繪製資料點
  5. 連接資料點形成填色多邊形:fill="color" opacity="0.2" stroke="color"
  6. 在每個軸線外緣標示標籤

輸出格式

將每個圖表包裹在 <figure> 元素中:

HTML:

<figure>
  <svg viewBox="0 0 560 380" style="max-width: 100%; height: auto; font-family: 'Inter', system-ui, sans-serif" role="img" aria-label="[description]">
    <title>[Chart Title]</title>
    <desc>[Full description with data points for screen readers]</desc>
    <!-- chart content -->
    <text x="280" y="372" text-anchor="middle" font-size="10" fill="currentColor" opacity="0.35">
      Source: [Source Name] ([Year])
    </text>
  </svg>
</figure>

MDX:

<figure className="chart-container" style={{margin: '2.5rem 0', textAlign: 'center', padding: '1.5rem', borderRadius: '12px'}}>
  <svg viewBox="0 0 560 380" style={{maxWidth: '100%', height: 'auto', fontFamily: "'Inter', system-ui, sans-serif"}} role="img" aria-label="[description]">
    <title>[Chart Title]</title>
    <desc>[Full description]</desc>
    {/* chart content with camelCase attributes */}
    <text x="280" y="372" textAnchor="middle" fontSize="10" fill="currentColor" opacity="0.35">
      Source: [Source Name] ([Year])
    </text>
  </svg>
</figure>

品質檢查清單(回傳前請確認)

  • 無硬編碼的文字顏色(全部使用 currentColor)
  • 無白色/淺色背景(透明或無)
  • 底部有來源歸屬文字
  • <svg> 上包含 role="img" 和 aria-label
  • <svg> 內部包含 <title> 和 <desc>
  • 此篇文章中尚未使用該圖表類型
  • 若為 MDX:所有屬性皆為 camelCase(屬性名稱中無連字號)
  • 資料值與來源資料完全一致
  • 色板僅使用核可的顏色
  • ViewBox 為 0 0 560 380(標準)或經合理調整的替代值

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

相關技能