Create a new chart or data visualization using Apache ECharts. Use when the user asks to add a chart, graph, visualization, plot, dashboard widget, or display data visually (line, bar, pie, area, scatter, radar, etc.).
Use this skill when the user asks to add a chart, graph, data visualization, or dashboard widget.
src/components/charts/EChart.tsx - Theme-aware ECharts wrapper (use this, never raw echarts)src/app/charts/_charts-demo.tsx - Reference implementations for all chart typesThe <EChart> component handles:
containLabel: trueimport { EChart } from '@/components/charts/EChart';
<EChart
height={300}
option={{
xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed'] },
yAxis: { type: 'value' },
series: [{ type: 'bar', data: [120, 200, 150] }],
}}
/>;
<EChart
height={300}
option={{
tooltip: { trigger: 'axis' },
legend: { data: ['Series A', 'Series B'], itemGap: 40, top: 0 },
grid: { top: 50 },
xAxis: { type: 'category', data: months, boundaryGap: false },
yAxis: { type: 'value' },
series: [
{ name: 'Series A', type: 'line', smooth: true, data: [...] },
{ name: 'Series B', type: 'line', smooth: true, data: [...] },
],
}}
/>
<EChart
height={300}
option={{
tooltip: { trigger: 'axis' },
legend: { data: ['2024', '2025'], itemGap: 40, top: 0 },
grid: { top: 50 },
xAxis: { type: 'category', data: ['Q1', 'Q2', 'Q3', 'Q4'] },
yAxis: { type: 'value' },
series: [
{
name: '2024',
type: 'bar',
data: [320, 332, 301, 434],
itemStyle: { borderRadius: [4, 4, 0, 0] },
},
{
name: '2025',
type: 'bar',
data: [420, 532, 491, 614],
itemStyle: { borderRadius: [4, 4, 0, 0] },
},
],
}}
/>
<EChart
height={300}
option={{
tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
legend: { orient: 'vertical', right: 10, top: 'center', itemGap: 30 },
series: [
{
type: 'pie',
radius: ['40%', '70%'], // Donut (use ['0%', '70%'] for solid pie)
center: ['40%', '50%'],
avoidLabelOverlap: false,
itemStyle: { borderRadius: 6, borderColor: 'transparent', borderWidth: 2 },
label: { show: false },
emphasis: { label: { show: true, fontWeight: 'bold' } },
data: [
{ value: 1048, name: 'Organic' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Referral' },
],
},
],
}}
/>
<EChart
height={300}
option={{
tooltip: { trigger: 'axis' },
xAxis: { type: 'category', data: days, boundaryGap: false },
yAxis: { type: 'value' },
series: [{
type: 'line',
smooth: true,
data: [...],
areaStyle: { opacity: 0.15 },
lineStyle: { width: 2 },
}],
}}
/>
<EChart
height={300}
option={{
tooltip: { trigger: 'item' },
legend: { data: ['Group A', 'Group B'], itemGap: 40, top: 0 },
grid: { top: 50 },
xAxis: { type: 'value', name: 'X Axis' },
yAxis: { type: 'value', name: 'Y Axis' },
series: [
{ name: 'Group A', type: 'scatter', data: [[x, y], ...], symbolSize: 10 },
{ name: 'Group B', type: 'scatter', data: [[x, y], ...], symbolSize: 10 },
],
}}
/>
<EChart
height={300}
option={{
tooltip: {},
legend: { data: ['Team A', 'Team B'], itemGap: 40, top: 0 },
radar: {
indicator: [
{ name: 'Performance', max: 100 },
{ name: 'Reliability', max: 100 },
// ...
],
shape: 'circle',
splitArea: { show: false },
},
series: [
{
type: 'radar',
data: [
{ value: [92, 85, 88, 95, 78], name: 'Team A' },
{ value: [78, 92, 75, 80, 95], name: 'Team B' },
],
areaStyle: { opacity: 0.1 },
},
],
}}
/>
Wrap charts in Card components:
import { Card } from '@/components/ui/Card';
import { EChart } from '@/components/charts/EChart';
<Card variant="elevated">
<Card.Header title="Chart Title" description="Brief description" />
<Card.Content>
<EChart height={300} option={...} />
</Card.Content>
</Card>
Grid layout for multiple charts:
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">{/* chart cards */}</div>
When using legends with multiple items, always set itemGap and adjust grid.top: