apexcharts-skill 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +100 -0
- package/SKILL.md +552 -0
- package/index.js +47 -0
- package/package.json +46 -0
- package/references/bar-charts.md +244 -0
- package/references/cartesian-charts.md +247 -0
- package/references/circular-charts.md +218 -0
- package/references/financial-charts.md +157 -0
- package/references/framework-wrappers.md +251 -0
- package/references/grid-charts.md +198 -0
- package/references/radar-charts.md +97 -0
- package/references/ssr.md +201 -0
- package/references/tree-shaking.md +154 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 ApexCharts
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# ApexCharts AI Skill
|
|
2
|
+
|
|
3
|
+
AI coding skill for building [ApexCharts.js](https://apexcharts.com/) charts and data visualizations. Works with Claude Code, Cursor, GitHub Copilot, and any AI coding assistant.
|
|
4
|
+
|
|
5
|
+
## What This Does
|
|
6
|
+
|
|
7
|
+
AI models frequently generate incorrect ApexCharts code — wrong series data formats, missing `render()` calls, broken formatter signatures, etc. This skill provides structured reference files that help AI assistants generate correct ApexCharts code on the first try.
|
|
8
|
+
|
|
9
|
+
### Coverage
|
|
10
|
+
|
|
11
|
+
- **16 chart types**: line, area, bar, pie, donut, radialBar, scatter, bubble, heatmap, candlestick, boxPlot, radar, polarArea, rangeBar, rangeArea, treemap
|
|
12
|
+
- **Correct data formats** for every chart type
|
|
13
|
+
- **16 common pitfalls** with wrong/correct code examples
|
|
14
|
+
- **Tree-shaking** and bundle optimization patterns
|
|
15
|
+
- **SSR** (server-side rendering) and hydration
|
|
16
|
+
- **Framework integration**: React, Vue 3, Angular
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Claude Code
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
mkdir -p .claude/skills
|
|
24
|
+
cd .claude/skills
|
|
25
|
+
git clone https://github.com/apexcharts/apexcharts-skill.git
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Cursor / Windsurf
|
|
29
|
+
|
|
30
|
+
Copy `.cursorrules` to your project root:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
curl -o .cursorrules https://raw.githubusercontent.com/apexcharts/apexcharts-skill/main/.cursorrules
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### GitHub Copilot
|
|
37
|
+
|
|
38
|
+
Reference `SKILL.md` in Copilot Chat: `@workspace #file:SKILL.md`
|
|
39
|
+
|
|
40
|
+
Or paste the contents of `.cursorrules` into Copilot's custom instructions.
|
|
41
|
+
|
|
42
|
+
### Generic AI Assistant
|
|
43
|
+
|
|
44
|
+
Paste the contents of `SKILL.md` into the system prompt or attach it as context.
|
|
45
|
+
|
|
46
|
+
### As an npm dependency
|
|
47
|
+
|
|
48
|
+
Tools that build on top of this skill (e.g. MCP servers, custom AI agents) can install it from npm and resolve absolute paths to the bundled markdown:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install apexcharts-skill
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
import { skillFile, referencesDir, referencePath } from 'apexcharts-skill';
|
|
56
|
+
import { readFile } from 'node:fs/promises';
|
|
57
|
+
|
|
58
|
+
const skill = await readFile(skillFile, 'utf8');
|
|
59
|
+
const barCharts = await readFile(referencePath('bar-charts.md'), 'utf8');
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Repository Structure
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
├── SKILL.md # Main entry point — read this first
|
|
66
|
+
├── .cursorrules # Self-contained version for Cursor/Windsurf
|
|
67
|
+
├── references/
|
|
68
|
+
│ ├── cartesian-charts.md # line, area, scatter, bubble, rangeArea
|
|
69
|
+
│ ├── bar-charts.md # bar, column, rangeBar, timeline/Gantt
|
|
70
|
+
│ ├── financial-charts.md # candlestick, boxPlot
|
|
71
|
+
│ ├── circular-charts.md # pie, donut, polarArea, radialBar
|
|
72
|
+
│ ├── grid-charts.md # heatmap, treemap
|
|
73
|
+
│ ├── radar-charts.md # radar
|
|
74
|
+
│ ├── tree-shaking.md # bundle optimization
|
|
75
|
+
│ ├── ssr.md # server-side rendering
|
|
76
|
+
│ └── framework-wrappers.md # React, Vue, Angular
|
|
77
|
+
└── install/
|
|
78
|
+
├── claude-code.md
|
|
79
|
+
├── cursor.md
|
|
80
|
+
└── copilot.md
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## How It Works
|
|
84
|
+
|
|
85
|
+
- **`SKILL.md`** is the main entry point containing critical rules, data format tables, formatter signatures, and all 16 pitfalls. An AI agent reading this file alone can generate correct code for any chart type.
|
|
86
|
+
- **`references/`** files provide deeper detail per chart family — full working examples, plotOptions, and family-specific pitfalls. AI agents load these on demand when the user needs a specific chart type.
|
|
87
|
+
- **`.cursorrules`** is a self-contained version for editors that don't support multi-file skills.
|
|
88
|
+
|
|
89
|
+
## Links
|
|
90
|
+
|
|
91
|
+
- [ApexCharts Documentation](https://apexcharts.com/docs/)
|
|
92
|
+
- [ApexCharts GitHub](https://github.com/apexcharts/apexcharts.js)
|
|
93
|
+
- [NPM Package](https://www.npmjs.com/package/apexcharts)
|
|
94
|
+
- [react-apexcharts](https://www.npmjs.com/package/react-apexcharts)
|
|
95
|
+
- [vue3-apexcharts](https://www.npmjs.com/package/vue3-apexcharts)
|
|
96
|
+
- [ng-apexcharts](https://www.npmjs.com/package/ng-apexcharts)
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apexcharts
|
|
3
|
+
description: >
|
|
4
|
+
AI skill for building ApexCharts.js charts and data visualizations.
|
|
5
|
+
Use when the user asks to create, configure, or troubleshoot any chart using ApexCharts
|
|
6
|
+
(line, area, bar, pie, donut, radialBar, scatter, bubble, heatmap, candlestick, boxPlot,
|
|
7
|
+
radar, polarArea, rangeBar, rangeArea, treemap). Covers correct data formats, lifecycle,
|
|
8
|
+
formatters, tree-shaking, SSR, and framework integration.
|
|
9
|
+
metadata:
|
|
10
|
+
author: ApexCharts
|
|
11
|
+
version: "1.0.0"
|
|
12
|
+
library_version: ">=5.0.0"
|
|
13
|
+
category: data-visualization
|
|
14
|
+
tags: [charts, visualization, javascript, typescript, svg, apexcharts]
|
|
15
|
+
docs: https://apexcharts.com/docs/
|
|
16
|
+
npm: apexcharts
|
|
17
|
+
github: https://github.com/apexcharts/apexcharts.js
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# ApexCharts AI Skill
|
|
21
|
+
|
|
22
|
+
## 1. Critical Rules
|
|
23
|
+
|
|
24
|
+
1. **Always call `chart.render()`** after `new ApexCharts(el, options)`. The constructor does not render.
|
|
25
|
+
2. **Always call `chart.destroy()`** before creating a new chart on the same element. Failing to do so causes memory leaks and duplicate charts (especially in React/Vue).
|
|
26
|
+
3. **Series data format is chart-type-specific.** Refer to the Data Format Table below. This is the #1 source of AI mistakes.
|
|
27
|
+
4. **`yaxis` must be an array** when using multiple y-axes. Each entry needs a `seriesName` to map to the correct series.
|
|
28
|
+
5. **`tooltip.shared` and `tooltip.intersect` are mutually exclusive.** `shared: true` shows all series at an x-position. `intersect: true` shows only the hovered point.
|
|
29
|
+
6. **Use `null` (not `undefined` or empty string)** for missing data points. `undefined` is silently ignored and breaks the chart.
|
|
30
|
+
7. **`chart.stacked: true`** only works with `bar` and `area` chart types.
|
|
31
|
+
8. **Responsive breakpoints** must be in ascending order in the `responsive` array.
|
|
32
|
+
9. **For mixed/combo charts**, set `type` on each individual series object, not just on `chart.type`.
|
|
33
|
+
10. **RadialBar values must be 0–100** (they represent percentages).
|
|
34
|
+
11. **Color hex values must include the `#` prefix** (e.g., `'#FF5733'`, not `'FF5733'`).
|
|
35
|
+
12. **Tree-shaking**: importing `apexcharts/core` gives you a bare class — you must also import chart-type entries and feature entries separately.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 2. Series Data Format Table
|
|
40
|
+
|
|
41
|
+
This is the most critical reference. Using the wrong data format is the #1 cause of broken charts.
|
|
42
|
+
|
|
43
|
+
### Axis Charts (line, area, bar, scatter, etc.)
|
|
44
|
+
|
|
45
|
+
| Chart Type | `chart.type` | Series Format | Minimal Example |
|
|
46
|
+
|---|---|---|---|
|
|
47
|
+
| Line | `'line'` | `[{ name, data: [number \| null] }]` or `[{ name, data: [{ x, y }] }]` | `series: [{ name: 'Sales', data: [30, 40, null, 50] }]` |
|
|
48
|
+
| Area | `'area'` | Same as line | `series: [{ name: 'Views', data: [10, 20, 30] }]` |
|
|
49
|
+
| Bar / Column | `'bar'` | Same as line. Use `plotOptions.bar.horizontal: true` for horizontal bars (default). Set `horizontal: false` for vertical columns. | `series: [{ name: 'Revenue', data: [44, 55, 41] }]` |
|
|
50
|
+
| Scatter | `'scatter'` | `[{ name, data: [{ x, y }] }]` — always use XY format | `series: [{ name: 'Points', data: [{ x: 1, y: 5 }, { x: 2, y: 10 }] }]` |
|
|
51
|
+
| Bubble | `'bubble'` | `[{ name, data: [{ x, y, z }] }]` — **z is required** (bubble size) | `series: [{ name: 'Data', data: [{ x: 1, y: 30, z: 10 }] }]` |
|
|
52
|
+
| Range Area | `'rangeArea'` | `[{ name, data: [{ x, y: [low, high] }] }]` | `series: [{ name: 'Temp', data: [{ x: 'Jan', y: [5, 15] }] }]` |
|
|
53
|
+
| Range Bar | `'rangeBar'` | `[{ name, data: [{ x, y: [start, end] }] }]` — for timeline/Gantt, use timestamps | `series: [{ name: 'Tasks', data: [{ x: 'Design', y: [1, 5] }] }]` |
|
|
54
|
+
| Candlestick | `'candlestick'` | `[{ data: [{ x, y: [O, H, L, C] }] }]` — array of 4: Open, High, Low, Close | `series: [{ data: [{ x: new Date('2024-01-01'), y: [51, 56, 48, 53] }] }]` |
|
|
55
|
+
| Box Plot | `'boxPlot'` | `[{ data: [{ x, y: [min, Q1, median, Q3, max] }] }]` — array of 5 | `series: [{ data: [{ x: 'Group A', y: [10, 20, 30, 40, 50] }] }]` |
|
|
56
|
+
| Heatmap | `'heatmap'` | `[{ name, data: [{ x, y: number }] }]` — y is the intensity value | `series: [{ name: 'Mon', data: [{ x: '10am', y: 45 }] }]` |
|
|
57
|
+
| Treemap | `'treemap'` | `[{ data: [{ x, y: number }] }]` — y is the area/value | `series: [{ data: [{ x: 'Item A', y: 100 }, { x: 'Item B', y: 60 }] }]` |
|
|
58
|
+
| Radar | `'radar'` | `[{ name, data: [number] }]` + `xaxis: { categories: [...] }` | `series: [{ name: 'Skill', data: [80, 50, 30, 40, 100] }]` |
|
|
59
|
+
|
|
60
|
+
### Non-Axis Charts (pie, donut, radialBar, polarArea)
|
|
61
|
+
|
|
62
|
+
These use a **flat number array** for `series`, NOT the object format:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// CORRECT — flat number array + labels
|
|
66
|
+
{
|
|
67
|
+
chart: { type: 'pie' }, // or 'donut', 'polarArea', 'radialBar'
|
|
68
|
+
series: [44, 55, 13, 43, 22],
|
|
69
|
+
labels: ['Team A', 'Team B', 'Team C', 'Team D', 'Team E']
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 3. Package / Module Map
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
# Full bundle (all chart types + all features)
|
|
79
|
+
import ApexCharts from 'apexcharts'
|
|
80
|
+
|
|
81
|
+
# Bare core (no chart types, no optional features — must register manually)
|
|
82
|
+
import ApexCharts from 'apexcharts/core'
|
|
83
|
+
|
|
84
|
+
# Per-type entry points (registers specific chart types + core)
|
|
85
|
+
import ApexCharts from 'apexcharts/line' # line, area, scatter, bubble, rangeArea
|
|
86
|
+
import ApexCharts from 'apexcharts/area' # same as /line
|
|
87
|
+
import ApexCharts from 'apexcharts/scatter' # same as /line
|
|
88
|
+
import ApexCharts from 'apexcharts/bubble' # same as /line
|
|
89
|
+
import ApexCharts from 'apexcharts/rangeArea' # same as /line
|
|
90
|
+
import ApexCharts from 'apexcharts/bar' # bar, column, rangeBar
|
|
91
|
+
import ApexCharts from 'apexcharts/column' # same as /bar
|
|
92
|
+
import ApexCharts from 'apexcharts/rangeBar' # same as /bar
|
|
93
|
+
import ApexCharts from 'apexcharts/candlestick' # candlestick, boxPlot
|
|
94
|
+
import ApexCharts from 'apexcharts/boxPlot' # same as /candlestick
|
|
95
|
+
import ApexCharts from 'apexcharts/pie' # pie, donut, polarArea
|
|
96
|
+
import ApexCharts from 'apexcharts/donut' # same as /pie
|
|
97
|
+
import ApexCharts from 'apexcharts/polarArea' # same as /pie
|
|
98
|
+
import ApexCharts from 'apexcharts/radialBar' # radialBar only
|
|
99
|
+
import ApexCharts from 'apexcharts/radar' # radar only
|
|
100
|
+
import ApexCharts from 'apexcharts/heatmap' # heatmap only
|
|
101
|
+
import ApexCharts from 'apexcharts/treemap' # treemap only
|
|
102
|
+
|
|
103
|
+
# Optional features (side-effect imports — just import, no default export needed)
|
|
104
|
+
import 'apexcharts/features/exports' # PNG/SVG/CSV export methods
|
|
105
|
+
import 'apexcharts/features/legend' # Interactive legend component
|
|
106
|
+
import 'apexcharts/features/toolbar' # Toolbar (zoom, pan, download buttons)
|
|
107
|
+
import 'apexcharts/features/annotations' # X/Y/point/text/image annotations
|
|
108
|
+
import 'apexcharts/features/keyboard' # Keyboard navigation (accessibility)
|
|
109
|
+
import 'apexcharts/features/all' # All features at once
|
|
110
|
+
|
|
111
|
+
# SSR (server-side rendering)
|
|
112
|
+
import ApexCharts from 'apexcharts/ssr' # Node.js: renderToString, renderToHTML
|
|
113
|
+
import ApexCharts from 'apexcharts/client' # Browser: explicit client import for hydration
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Note:** When using `apexcharts` (full bundle), all chart types and features are included automatically. Tree-shaking entries (`/core`, `/line`, etc.) are for reducing bundle size.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 4. Core Lifecycle Pattern
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import ApexCharts from 'apexcharts'
|
|
124
|
+
|
|
125
|
+
// 1. Define options
|
|
126
|
+
const options = {
|
|
127
|
+
chart: {
|
|
128
|
+
type: 'line',
|
|
129
|
+
height: 350
|
|
130
|
+
},
|
|
131
|
+
series: [{
|
|
132
|
+
name: 'Sales',
|
|
133
|
+
data: [30, 40, 35, 50, 49, 60, 70]
|
|
134
|
+
}],
|
|
135
|
+
xaxis: {
|
|
136
|
+
categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 2. Create chart instance
|
|
141
|
+
const chart = new ApexCharts(document.querySelector('#chart'), options)
|
|
142
|
+
|
|
143
|
+
// 3. Render (REQUIRED — constructor alone does not display the chart)
|
|
144
|
+
await chart.render()
|
|
145
|
+
|
|
146
|
+
// 4. Update data or options later
|
|
147
|
+
await chart.updateSeries([{
|
|
148
|
+
name: 'Sales',
|
|
149
|
+
data: [10, 20, 15, 30, 29, 40, 50]
|
|
150
|
+
}])
|
|
151
|
+
|
|
152
|
+
// Or merge new config options
|
|
153
|
+
await chart.updateOptions({
|
|
154
|
+
title: { text: 'Updated Chart' }
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
// 5. Destroy when done (REQUIRED before unmounting in SPA frameworks)
|
|
158
|
+
chart.destroy()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 5. Formatter Function Signatures
|
|
164
|
+
|
|
165
|
+
| Config Path | Signature | Returns |
|
|
166
|
+
|---|---|---|
|
|
167
|
+
| `xaxis.labels.formatter` | `(value: string \| number, timestamp?: number, opts?) => string` | Formatted x-axis tick label |
|
|
168
|
+
| `yaxis.labels.formatter` | `(value: number, opts?) => string` | Formatted y-axis tick label |
|
|
169
|
+
| `tooltip.x.formatter` | `(value: number, opts?) => string` | Tooltip x-value text |
|
|
170
|
+
| `tooltip.y.formatter` | `(value: number, opts?) => string` | Tooltip y-value text |
|
|
171
|
+
| `tooltip.y.title.formatter` | `(seriesName: string, opts?) => string` | Tooltip series title |
|
|
172
|
+
| `tooltip.z.formatter` | `(value: number) => string` | Tooltip z-value (bubble) |
|
|
173
|
+
| `dataLabels.formatter` | `(value: number \| string \| number[], opts?) => string \| number` | Data label text |
|
|
174
|
+
| `legend.formatter` | `(legendName: string, opts?) => string` | Legend item text |
|
|
175
|
+
| `plotOptions.pie.donut.labels.value.formatter` | `(val: string) => string` | Donut center value |
|
|
176
|
+
| `plotOptions.pie.donut.labels.total.formatter` | `(w: { globals, config }) => string` | Donut center total |
|
|
177
|
+
| `plotOptions.radialBar.dataLabels.value.formatter` | `(val: number) => string` | RadialBar center value |
|
|
178
|
+
|
|
179
|
+
**Important:** All formatters must return a `string` (or `number` for `dataLabels.formatter`). Never return `undefined`.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 6. Pitfalls & Anti-Patterns
|
|
184
|
+
|
|
185
|
+
### Pitfall 1: Wrong series data format for chart type
|
|
186
|
+
|
|
187
|
+
❌ **WRONG** — pie chart with axis-chart series format:
|
|
188
|
+
```js
|
|
189
|
+
{ chart: { type: 'pie' }, series: [{ name: 'A', data: [44, 55] }] }
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
✅ **CORRECT** — pie chart uses flat number array + labels:
|
|
193
|
+
```js
|
|
194
|
+
{ chart: { type: 'pie' }, series: [44, 55, 13], labels: ['A', 'B', 'C'] }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Pitfall 2: Not calling render()
|
|
198
|
+
|
|
199
|
+
❌ **WRONG** — chart never appears:
|
|
200
|
+
```js
|
|
201
|
+
const chart = new ApexCharts(el, options)
|
|
202
|
+
// Missing render() call!
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
✅ **CORRECT**:
|
|
206
|
+
```js
|
|
207
|
+
const chart = new ApexCharts(el, options)
|
|
208
|
+
await chart.render()
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Pitfall 3: Not destroying before re-creating (React/Vue memory leak)
|
|
212
|
+
|
|
213
|
+
❌ **WRONG** — creates duplicate charts:
|
|
214
|
+
```js
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
const chart = new ApexCharts(ref.current, options)
|
|
217
|
+
chart.render()
|
|
218
|
+
}, [options])
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
✅ **CORRECT** — destroy on cleanup:
|
|
222
|
+
```js
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
const chart = new ApexCharts(ref.current, options)
|
|
225
|
+
chart.render()
|
|
226
|
+
return () => chart.destroy()
|
|
227
|
+
}, [options])
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Pitfall 4: Mixing xaxis.type with wrong data format
|
|
231
|
+
|
|
232
|
+
❌ **WRONG** — datetime axis with string dates (not timestamps):
|
|
233
|
+
```js
|
|
234
|
+
{
|
|
235
|
+
xaxis: { type: 'datetime' },
|
|
236
|
+
series: [{ data: [{ x: 'January 2024', y: 30 }] }]
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
✅ **CORRECT** — datetime axis with timestamps or Date objects:
|
|
241
|
+
```js
|
|
242
|
+
{
|
|
243
|
+
xaxis: { type: 'datetime' },
|
|
244
|
+
series: [{ data: [{ x: new Date('2024-01-01').getTime(), y: 30 }] }]
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Also: do NOT use `xaxis.categories` when your data already has `{ x, y }` format — categories are ignored.
|
|
249
|
+
|
|
250
|
+
### Pitfall 5: Multiple y-axes not as array
|
|
251
|
+
|
|
252
|
+
❌ **WRONG** — yaxis as single object:
|
|
253
|
+
```js
|
|
254
|
+
{
|
|
255
|
+
series: [{ name: 'Revenue', data: [...] }, { name: 'Profit', data: [...] }],
|
|
256
|
+
yaxis: { title: { text: 'Revenue' } }
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
✅ **CORRECT** — yaxis as array with seriesName mapping:
|
|
261
|
+
```js
|
|
262
|
+
{
|
|
263
|
+
series: [{ name: 'Revenue', data: [...] }, { name: 'Profit', data: [...] }],
|
|
264
|
+
yaxis: [
|
|
265
|
+
{ seriesName: 'Revenue', title: { text: 'Revenue ($)' } },
|
|
266
|
+
{ seriesName: 'Profit', opposite: true, title: { text: 'Profit (%)' } }
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Pitfall 6: tooltip.shared vs tooltip.intersect
|
|
272
|
+
|
|
273
|
+
❌ **WRONG** — both enabled (conflicting):
|
|
274
|
+
```js
|
|
275
|
+
{ tooltip: { shared: true, intersect: true } }
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
✅ **CORRECT** — pick one mode:
|
|
279
|
+
```js
|
|
280
|
+
// Mode A: Show all series values at x-position (default for line/area)
|
|
281
|
+
{ tooltip: { shared: true, intersect: false } }
|
|
282
|
+
|
|
283
|
+
// Mode B: Show only hovered data point (better for scatter)
|
|
284
|
+
{ tooltip: { shared: false, intersect: true } }
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Pitfall 7: Wrong formatter signatures
|
|
288
|
+
|
|
289
|
+
❌ **WRONG** — using y-axis formatter signature for tooltip:
|
|
290
|
+
```js
|
|
291
|
+
{
|
|
292
|
+
tooltip: { y: { formatter: (val, timestamp, opts) => `$${val}` } }
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
✅ **CORRECT** — tooltip.y.formatter only receives `(val, opts)`:
|
|
297
|
+
```js
|
|
298
|
+
{
|
|
299
|
+
tooltip: { y: { formatter: (val, opts) => `$${val}` } },
|
|
300
|
+
yaxis: { labels: { formatter: (val) => `$${val.toFixed(0)}` } }
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Pitfall 8: undefined instead of null for missing data
|
|
305
|
+
|
|
306
|
+
❌ **WRONG** — undefined breaks the chart:
|
|
307
|
+
```js
|
|
308
|
+
{ series: [{ data: [10, undefined, 30, undefined, 50] }] }
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
✅ **CORRECT** — use null:
|
|
312
|
+
```js
|
|
313
|
+
{ series: [{ data: [10, null, 30, null, 50] }] }
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Pitfall 9: Stacking on unsupported chart types
|
|
317
|
+
|
|
318
|
+
❌ **WRONG** — stacking on scatter chart:
|
|
319
|
+
```js
|
|
320
|
+
{ chart: { type: 'scatter', stacked: true } }
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
✅ **CORRECT** — stacking only works on bar and area:
|
|
324
|
+
```js
|
|
325
|
+
{ chart: { type: 'bar', stacked: true } }
|
|
326
|
+
// or
|
|
327
|
+
{ chart: { type: 'area', stacked: true } }
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Pitfall 10: Mixed/combo charts missing per-series type
|
|
331
|
+
|
|
332
|
+
❌ **WRONG** — no type on individual series:
|
|
333
|
+
```js
|
|
334
|
+
{
|
|
335
|
+
chart: { type: 'line' },
|
|
336
|
+
series: [
|
|
337
|
+
{ name: 'Sales', data: [10, 20, 30] }, // renders as line
|
|
338
|
+
{ name: 'Profit', data: [5, 12, 18] } // also renders as line!
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
✅ **CORRECT** — set type per series:
|
|
344
|
+
```js
|
|
345
|
+
{
|
|
346
|
+
chart: { type: 'line' },
|
|
347
|
+
series: [
|
|
348
|
+
{ name: 'Sales', type: 'column', data: [10, 20, 30] },
|
|
349
|
+
{ name: 'Profit', type: 'line', data: [5, 12, 18] }
|
|
350
|
+
]
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Pitfall 11: RadialBar values > 100
|
|
355
|
+
|
|
356
|
+
❌ **WRONG** — raw values (renders incorrectly):
|
|
357
|
+
```js
|
|
358
|
+
{ chart: { type: 'radialBar' }, series: [340, 520, 190] }
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
✅ **CORRECT** — use percentages 0–100:
|
|
362
|
+
```js
|
|
363
|
+
{ chart: { type: 'radialBar' }, series: [76, 67, 61], labels: ['A', 'B', 'C'] }
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Pitfall 12: Colors without # prefix
|
|
367
|
+
|
|
368
|
+
❌ **WRONG**:
|
|
369
|
+
```js
|
|
370
|
+
{ colors: ['FF5733', '33FF57'] }
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
✅ **CORRECT**:
|
|
374
|
+
```js
|
|
375
|
+
{ colors: ['#FF5733', '#33FF57'] }
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Pitfall 13: Responsive breakpoints not ascending
|
|
379
|
+
|
|
380
|
+
❌ **WRONG** — descending order:
|
|
381
|
+
```js
|
|
382
|
+
{ responsive: [{ breakpoint: 1024, options: {...} }, { breakpoint: 480, options: {...} }] }
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
✅ **CORRECT** — ascending order:
|
|
386
|
+
```js
|
|
387
|
+
{ responsive: [{ breakpoint: 480, options: {...} }, { breakpoint: 1024, options: {...} }] }
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Pitfall 14: Tree-shaking — missing feature imports
|
|
391
|
+
|
|
392
|
+
❌ **WRONG** — toolbar/legend/annotations silently missing:
|
|
393
|
+
```js
|
|
394
|
+
import ApexCharts from 'apexcharts/line'
|
|
395
|
+
// No feature imports! Legend, toolbar, annotations won't appear.
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
✅ **CORRECT** — import needed features:
|
|
399
|
+
```js
|
|
400
|
+
import ApexCharts from 'apexcharts/line'
|
|
401
|
+
import 'apexcharts/features/legend'
|
|
402
|
+
import 'apexcharts/features/toolbar'
|
|
403
|
+
import 'apexcharts/features/annotations'
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Pitfall 15: SSR — wrong import path
|
|
407
|
+
|
|
408
|
+
❌ **WRONG** — using browser bundle in Node.js:
|
|
409
|
+
```js
|
|
410
|
+
// On server:
|
|
411
|
+
import ApexCharts from 'apexcharts'
|
|
412
|
+
await ApexCharts.renderToString(options) // renderToString doesn't exist!
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
✅ **CORRECT** — use SSR entry point:
|
|
416
|
+
```js
|
|
417
|
+
// On server:
|
|
418
|
+
import ApexCharts from 'apexcharts/ssr'
|
|
419
|
+
const svg = await ApexCharts.renderToString(options)
|
|
420
|
+
|
|
421
|
+
// On client (for hydration):
|
|
422
|
+
import ApexCharts from 'apexcharts' // or 'apexcharts/client'
|
|
423
|
+
ApexCharts.hydrate(document.querySelector('#chart'))
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Pitfall 16: updateOptions vs updateSeries vs appendData
|
|
427
|
+
|
|
428
|
+
❌ **WRONG** — full updateOptions just to change data:
|
|
429
|
+
```js
|
|
430
|
+
chart.updateOptions({ series: [{ data: newData }] })
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
✅ **CORRECT** — use the right method:
|
|
434
|
+
```js
|
|
435
|
+
// Replace all series data (most common)
|
|
436
|
+
await chart.updateSeries([{ name: 'Sales', data: newData }])
|
|
437
|
+
|
|
438
|
+
// Add data points to existing series (real-time streaming)
|
|
439
|
+
await chart.appendData([{ data: [newPoint] }])
|
|
440
|
+
|
|
441
|
+
// Change config (title, colors, axis, etc.)
|
|
442
|
+
await chart.updateOptions({ title: { text: 'New Title' } })
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## 7. API Methods Quick Reference
|
|
448
|
+
|
|
449
|
+
### Instance Methods
|
|
450
|
+
|
|
451
|
+
| Method | Description |
|
|
452
|
+
|---|---|
|
|
453
|
+
| `render()` | Renders the chart. Returns `Promise<ApexCharts>`. |
|
|
454
|
+
| `destroy()` | Destroys chart instance and removes DOM elements. |
|
|
455
|
+
| `updateOptions(options, redraw?, animate?, updateSyncedCharts?)` | Merges new options and re-renders. Returns `Promise`. |
|
|
456
|
+
| `updateSeries(newSeries, animate?)` | Replaces series data. Returns `Promise`. |
|
|
457
|
+
| `appendSeries(newSeries, animate?)` | Appends a new series to existing ones. Returns `Promise`. |
|
|
458
|
+
| `appendData(newData)` | Appends data points to each series. Returns `Promise`. |
|
|
459
|
+
| `toggleSeries(seriesName)` | Show/hide series by name. |
|
|
460
|
+
| `showSeries(seriesName)` | Show a hidden series. |
|
|
461
|
+
| `hideSeries(seriesName)` | Hide a visible series. |
|
|
462
|
+
| `resetSeries(shouldUpdateChart?, shouldResetZoom?)` | Resets to initial series data. |
|
|
463
|
+
| `zoomX(min, max)` | Programmatically zoom x-axis. |
|
|
464
|
+
| `addXaxisAnnotation(opts)` | Add x-axis annotation dynamically. |
|
|
465
|
+
| `addYaxisAnnotation(opts)` | Add y-axis annotation dynamically. |
|
|
466
|
+
| `addPointAnnotation(opts)` | Add point annotation dynamically. |
|
|
467
|
+
| `removeAnnotation(id)` | Remove annotation by id. |
|
|
468
|
+
| `clearAnnotations()` | Remove all annotations. |
|
|
469
|
+
| `dataURI(options?)` | Export chart as data URI. Returns `Promise`. |
|
|
470
|
+
| `getSvgString(scale?)` | Get chart SVG markup. Returns `Promise<string>`. |
|
|
471
|
+
| `exportToCSV(options?)` | Trigger CSV download. |
|
|
472
|
+
| `setLocale(localeName)` | Switch locale. |
|
|
473
|
+
| `toggleDataPointSelection(seriesIndex, dataPointIndex?)` | Select/deselect data point. |
|
|
474
|
+
| `getState()` | Returns snapshot of chart state. |
|
|
475
|
+
| `addEventListener(name, handler)` | Subscribe to chart event. |
|
|
476
|
+
| `removeEventListener(name, handler)` | Unsubscribe from chart event. |
|
|
477
|
+
|
|
478
|
+
### Static Methods
|
|
479
|
+
|
|
480
|
+
| Method | Description |
|
|
481
|
+
|---|---|
|
|
482
|
+
| `ApexCharts.exec(chartID, fn, ...args)` | Call method on chart by its `chart.id`. |
|
|
483
|
+
| `ApexCharts.getChartByID(chartID)` | Get chart instance by id. |
|
|
484
|
+
| `ApexCharts.merge(target, source)` | Deep-merge objects. |
|
|
485
|
+
| `ApexCharts.use(typeMap)` | Register chart type constructors (tree-shaking). |
|
|
486
|
+
| `ApexCharts.registerFeatures(featureMap)` | Register optional feature modules. |
|
|
487
|
+
|
|
488
|
+
### SSR Static Methods (available with `apexcharts/ssr`)
|
|
489
|
+
|
|
490
|
+
| Method | Description |
|
|
491
|
+
|---|---|
|
|
492
|
+
| `ApexCharts.renderToString(options)` | Render chart to SVG string (Node.js). |
|
|
493
|
+
| `ApexCharts.renderToHTML(options)` | Render chart to HTML string with wrapper (Node.js). |
|
|
494
|
+
| `ApexCharts.hydrate(element)` | Hydrate server-rendered chart (browser). |
|
|
495
|
+
| `ApexCharts.hydrateAll()` | Hydrate all server-rendered charts on page. |
|
|
496
|
+
| `ApexCharts.isHydrated(element)` | Check if element is already hydrated. |
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## 8. Chart Events
|
|
501
|
+
|
|
502
|
+
```js
|
|
503
|
+
{
|
|
504
|
+
chart: {
|
|
505
|
+
events: {
|
|
506
|
+
// Lifecycle
|
|
507
|
+
beforeMount: (chart, options) => {},
|
|
508
|
+
mounted: (chart, options) => {},
|
|
509
|
+
updated: (chart, options) => {},
|
|
510
|
+
animationEnd: (chart, options) => {},
|
|
511
|
+
|
|
512
|
+
// User interaction
|
|
513
|
+
click: (event, chart, options) => {},
|
|
514
|
+
mouseMove: (event, chart, options) => {},
|
|
515
|
+
mouseLeave: (event, chart, options) => {},
|
|
516
|
+
legendClick: (chart, seriesIndex, options) => {},
|
|
517
|
+
markerClick: (event, chart, options) => {},
|
|
518
|
+
xAxisLabelClick: (event, chart, options) => {},
|
|
519
|
+
|
|
520
|
+
// Data point events
|
|
521
|
+
dataPointSelection: (event, chart, options) => {},
|
|
522
|
+
dataPointMouseEnter: (event, chart, options) => {},
|
|
523
|
+
dataPointMouseLeave: (event, chart, options) => {},
|
|
524
|
+
|
|
525
|
+
// Zoom & pan
|
|
526
|
+
beforeZoom: (chart, { xaxis }) => {}, // return false to cancel
|
|
527
|
+
zoomed: (chart, { xaxis }) => {},
|
|
528
|
+
beforeResetZoom: (chart, options) => {}, // return false to cancel
|
|
529
|
+
scrolled: (chart, { xaxis }) => {},
|
|
530
|
+
selection: (chart, { xaxis, yaxis }) => {},
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
## 9. Reference Routing Table
|
|
539
|
+
|
|
540
|
+
For detailed chart-family-specific options, data format variants, and full working examples, refer to:
|
|
541
|
+
|
|
542
|
+
| Topic | Reference File |
|
|
543
|
+
|---|---|
|
|
544
|
+
| Line, Area, Scatter, Bubble, Range Area | `references/cartesian-charts.md` |
|
|
545
|
+
| Bar, Column, Range Bar, Timeline/Gantt | `references/bar-charts.md` |
|
|
546
|
+
| Candlestick, Box Plot | `references/financial-charts.md` |
|
|
547
|
+
| Pie, Donut, Polar Area, Radial Bar | `references/circular-charts.md` |
|
|
548
|
+
| Heatmap, Treemap | `references/grid-charts.md` |
|
|
549
|
+
| Radar | `references/radar-charts.md` |
|
|
550
|
+
| Tree-shaking, Bundle optimization | `references/tree-shaking.md` |
|
|
551
|
+
| Server-side rendering, Hydration | `references/ssr.md` |
|
|
552
|
+
| React, Vue, Angular integration | `references/framework-wrappers.md` |
|