Common chart types
🎯 Introduction
Now that you understand option, the next question is which chart to use. This article covers the key configuration for line, bar, pie, and scatter charts and explains when to choose each one.
🧱 Line charts: showing trends
Line charts (type: 'line') show trends over time, such as weekly visits or monthly temperatures:
series: [
{
name: 'Visits',
type: 'line',
data: [820, 932, 901, 934, 1290, 1330, 1320],
},
],
Two frequently used properties:
smooth: true: draws a smoother curve instead of straight line segments.areaStyle: {}: fills the area below the line to create an area chart, emphasizing overall magnitude.
series: [
{
name: 'Visits',
type: 'line',
smooth: true,
areaStyle: {},
data: [820, 932, 901, 934, 1290, 1330, 1320],
},
],
Here is a live chart with a smooth curve and area fill:
🧱 Bar charts: comparing values
Bar charts (type: 'bar') are useful for comparing values across categories:
series: [
{
name: 'Sales',
type: 'bar',
data: [120, 200, 150, 80, 70],
},
],
The commonly used barWidth property controls bar width and accepts percentages:
series: [
{
name: 'Sales',
type: 'bar',
barWidth: '40%',
data: [120, 200, 150, 80, 70],
},
],
🧱 Pie charts: showing proportions
Pie charts (type: 'pie') show parts of a whole, such as traffic sources. Unlike the previous two chart types, they do not need axes. Their data format also differs: each entry is a { name, value } object:
series: [
{
name: 'Traffic sources',
type: 'pie',
radius: '50%',
data: [
{ name: 'Search engines', value: 1048 },
{ name: 'Direct visits', value: 735 },
{ name: 'Email marketing', value: 580 },
],
},
],
radiuscontrols the radius; a percentage makes it relative to the container size.- Set
radiusto an array such as['40%', '70%']to leave a hole in the center and create a doughnut chart.
Here is the live rendering of this pie chart:
🧱 Scatter charts: showing distributions
Scatter charts (type: 'scatter') reveal relationships between two numeric variables, such as height and weight. The data is a two-dimensional array with [x, y] entries:
series: [
{
name: 'Users',
type: 'scatter',
data: [
[168, 60],
[175, 72],
[160, 50],
[180, 85],
],
},
],
Set both xAxis and yAxis to type: 'value', since both dimensions are numeric.
Here is the live chart, with value axes in both directions:
💡 Choosing among the four chart types
| Chart | type | Use case | Data format |
|---|---|---|---|
| Line | 'line' | Trends over time | [1, 2, 3] |
| Bar | 'bar' | Comparing categories | [1, 2, 3] |
| Pie | 'pie' | Parts of a whole | [{ name, value }] |
| Scatter | 'scatter' | Relationships between two numeric variables | [[x, y]] |
[1, 2, 3] directly may not throw an error, but the result will not be what you expect. Always check the data format when switching chart types.❓ Questions and answers
Q1: Can line and bar series share a chart?
Yes. Add one entry with 'line' and another with 'bar' to series to create a mixed chart.
Q2: Why do pie charts omit xAxis and yAxis?
Pie charts do not use a Cartesian coordinate system. They are laid out around a center point, so axis configuration does not affect them.
Q3: Is a doughnut chart a separate chart type?
No. It is a pie chart with inner and outer radii, such as ['40%', '70%'].
Q4: What if there are too many overlapping scatter points?
Reduce symbolSize. ECharts 6 also supports a jitter parameter to spread overlapping points apart. For now, focus on the basics.
🧪 Practice
Render the following traffic-source data as a doughnut chart:
- Use
'pie'and setradiusto['40%', '70%']. - Data: Search engines 1048, Direct visits 735, Email marketing 580.
- Add
tooltipwith an'item'trigger and alegend.
chart.setOption({
// Write your code here
});
🎉 You now know the four most common chart types! Next, we will customize styles and themes to improve their appearance.
