ECharts Pie Chart
In previous chapters we learned to draw a simple bar chart with ECharts; in this chapter we will draw a pie chart.
A pie chart mainly shows the proportion of different categories in the total through the arc of sectors. Its data format is simpler than a bar chart, with only one-dimensional values and no need to specify categories. Since it is not on a Cartesian coordinate system, xAxis and yAxis are not needed.
Example
myChart
.
setOption
(
{
series
:
[
{
name
:
'
Traffic Source
'
,
type
:
'
pie
'
,
//
Set the chart type to pie
radius
:
'
55%
'
,
//
The radius of the pie chart; the outer radius is 55% of the smaller of the container's height and width.
data
:
[
//
Data array, where name is the data item name and value is the data item value
{
value
:
235
,
name
:
'
Video Ads
'
}
,
{
value
:
274
,
name
:
'
Affiliate Ads
'
}
,
{
value
:
310
,
name
:
'
Email Marketing
'
}
,
{
value
:
335
,
name
:
'
Direct Access
'
}
,
{
value
:
400
,
name
:
'
Search engine
'
}
]
}
]
}
)
Try it »
We can also display the pie chart as a Nightingale rose chart by setting the parameter roseType: 'angle'.
Example
option
=
{
series
:
[
{
name
:
'
Traffic Source
'
,
type
:
'
pie
'
,
radius
:
'
55%
'
,
roseType
:
'
angle
'
,
data
:
[
{
value
:
235
,
name
:
'
Video Ads
'
}
,
{
value
:
274
,
name
:
'
Affiliate Ads
'
}
,
{
value
:
310
,
name
:
'
Email Marketing
'
}
,
{
value
:
335
,
name
:
'
Direct Access
'
}
,
{
value
:
400
,
name
:
'
Search engine
'
}
]
}
]
}
;
Try it »
Shadow configuration
The itemStyle parameter can set shadows, transparency, color, border color, border width, and so on:
Example
option
=
{
series
:
[
{
name
:
'
Traffic Source
'
,
type
:
'
pie
'
,
radius
:
'
55%
'
,
data
:
[
{
value
:
235
,
name
:
'
Video Ads
'
}
,
{
value
:
274
,
name
:
'
Affiliate Ads
'
}
,
{
value
:
310
,
name
:
'
Email Marketing
'
}
,
{
value
:
335
,
name
:
'
Direct Access
'
}
,
{
value
:
400
,
name
:
'
Search engine
'
}
]
,
roseType
:
'
angle
'
,
itemStyle
:
{
normal
:
{
shadowBlur
:
200
,
shadowColor
:
'
rgba(0, 0, 0, 0.5)
'
}
}
}
]
}
;
Try it »