Certainly! Below are standardized JSON structure templates for the core ECharts option object for the following common chart types: Bar, Line, Scatter, and Pie. Each template includes:
- A basic JSON structure with data binding points.
- Illustration of how multiple data series are represented (where applicable).
- Notes on whether the chart type typically supports multiple data series.
- Corresponding TypeScript interfaces describing the shape of each JSON structure.
These templates are designed to establish a standard format to facilitate data transformation and integration with ECharts.
📊 1. Bar Chart
✅ Supports multiple data series.
🔧 JSON Template:
{
"title": {
"text": "Bar Chart Example"
},
"tooltip": {},
"legend": {
"data": ["Series A", "Series B"]
},
"xAxis": {
"type": "category",
"data": ["Category 1", "Category 2", "Category 3"]
},
"yAxis": {
"type": "value"
},
"series": [
{
"name": "Series A",
"type": "bar",
"data": [120, 200, 150]
},
{
"name": "Series B",
"type": "bar",
"data": [80, 100, 130]
}
]
}
🧾 TypeScript Interface:
interface BarChartOption {
title?: {
text: string;
};
tooltip?: Record<string, any>;
legend?: {
data: string[];
};
xAxis: {
type: 'category';
data: string[];
};
yAxis: {
type: 'value';
};
series: Array<{
name: string;
type: 'bar';
data: number[];
}>;
}
📈 2. Line Chart
✅ Supports multiple data series.
🔧 JSON Template:
{
"title": {
"text": "Line Chart Example"
},
"tooltip": {
"trigger": "axis"
},
"legend": {
"data": ["Series A", "Series B"]
},
"xAxis": {
"type": "category",
"data": ["Jan", "Feb", "Mar"]
},
"yAxis": {
"type": "value"
},
"series": [
{
"name": "Series A",
"type": "line",
"data": [150, 230, 224]
},
{
"name": "Series B",
"type": "line",
"data": [120, 282, 291]
}
]
}
🧾 TypeScript Interface:
interface LineChartOption {
title?: {
text: string;
};
tooltip?: {
trigger?: string;
};
legend?: {
data: string[];
};
xAxis: {
type: 'category';
data: string[];
};
yAxis: {
type: 'value';
};
series: Array<{
name: string;
type: 'line';
data: number[];
}>;
}
🔵 3. Scatter Chart
✅ Supports multiple data series.
🔧 JSON Template:
{
"title": {
"text": "Scatter Chart Example"
},
"tooltip": {
"trigger": "item"
},
"legend": {
"data": ["Series A", "Series B"]
},
"xAxis": {
"type": "value"
},
"yAxis": {
"type": "value"
},
"series": [
{
"name": "Series A",
"type": "scatter",
"data": [
[10, 8],
[15, 12],
[20, 18]
]
},
{
"name": "Series B",
"type": "scatter",
"data": [
[5, 3],
[12, 9],
[18, 15]
]
}
]
}
🧾 TypeScript Interface:
interface ScatterChartOption {
title?: {
text: string;
};
tooltip?: {
trigger?: string;
};
legend?: {
data: string[];
};
xAxis: {
type: 'value';
};
yAxis: {
type: 'value';
};
series: Array<{
name: string;
type: 'scatter';
data: [number, number][];
}>;
}
🥧 4. Pie Chart
❌ Typically does NOT support multiple data series in the same chart instance (though multiple pies can be rendered, it's less common and not standard).
🔧 JSON Template:
{
"title": {
"text": "Pie Chart Example"
},
"tooltip": {
"trigger": "item"
},
"legend": {
"orient": "vertical",
"left": "left"
},
"series": [
{
"name": "Access Source",
"type": "pie",
"radius": "50%",
"data": [
{ "value": 1048, "name": "Search Engine" },
{ "value": 735, "name": "Direct" },
{ "value": 580, "name": "Email" },
{ "value": 484, "name": "Union Ads" },
{ "value": 300, "name": "Video Ads" }
]
}
]
}
🧾 TypeScript Interface:
interface PieChartOption {
title?: {
text: string;
};
tooltip?: {
trigger?: string;
};
legend?: {
orient?: string;
left?: string;
};
series: Array<{
name: string;
type: 'pie';
radius: string | [string, string];
data: Array<{
value: number;
name: string;
}>;
}>;
}
📌 Summary of Multi-Series Support:
| Chart Type | Supports Multiple Series | Notes |
|---|
| Bar | ✅ Yes | Each series represents a bar group; grouped or stacked bars possible |
| Line | ✅ Yes | Each series is a separate line |
| Scatter | ✅ Yes | Each series is a separate scatter group |
| Pie | ❌ No (typically) | Usually one series; multiple pies require special layout |
These templates and interfaces provide a standardized foundation for transforming and validating data for ECharts visualizations in TypeScript-based applications.