@codecraftkit
Documentation
A pie chart (or a circle chart) is a circular statistical graphic, which is divided into slices to illustrate numerical proportion.
This component is based on AmCharts v4
const data = [{"category": "Lithuania","value": 501.9}, {"category": "Czech Republic","value": 301.9}, {"category": "Ireland","value": 201.1}, {"category": "Germany","value": 165.8}, {"category": "Australia","value": 139.9}, {"category": "Austria","value": 128.3}, {"category": "UK","value": 99}, {"category": "Belgium","value": 60}, {"category": "Netherlands","value": 50}];
<Chart data={data} type="PieChart" />
Note: Same as XYChart, The Pie chart will take category and values in the data by default... to customize this see the next example.
<Chart data={data} type="PieChart" options={optionsExample}/>
The Options prop is an object that allows to customize the chart
To customize the PieChart you have to pass a object inside options called pieChart and inside it all the options you want to modify
For example lets see this data
[{"country": "Lithuania","litres": 50}, {"country": "Czech Republic","litres":20}, {"country": "Ireland","litres": 30}, {"country": "Germany","litres": 90}, {"country": "Australia","litres": 75}, {"country": "Austria","litres": 64.2}, {"country": "UK","litres": 105.9}, {"country": "Belgium","litres": 20}, {"country": "Netherlands","litres": 25}];
If we use this data like this, the Chart won't do anything because there aren't any value
or category
field, so we need to tell the chart to get the params country
and litres
from the data using options like this:
const optionsExample = {//PieChart OptionspieChart: {//activate legendlegend: true,//To modify the size of the inner circleradiusInside: 50,series: {category: 'country',value: 'litres',//Pie Chart Titlename: 'Countries Water',},}};
Note: We also make bigger the inner circle and activate the legend.
To change the color of each item you have to put in the data a field called color, like this:
const optionsColorData = [{"country": "Lithuania","litres": 501,"color": am4core.color("#ED1C24")}, {"country": "Czechia","litres": 301,"color": am4core.color("#235789")}, {"country": "Ireland","litres": 201,"color": am4core.color("#F1D302")}, {"country": "Germany","litres": 165,"color": am4core.color("#020100")}];
Note: You don't have to change options to use the color from the data
To use am4core you have to import it, like this:
To change the PieChart to a 3d one you have to tell it in the props like this:
const options3dExample = {//PieChart OptionspieChart: {//To activate the 3d charttype:'PieChart3D',//activate legendlegend: true,//To modify the size of the inner circleradiusInside: 50,series: {//Change the serie a type 3d mode//this only works when the chart have PieChart3D typetype:'PieSeries3D',category: 'country',value: 'litres',//Pie Chart Titlename: 'Countries Water',},}};
Note: We'll use the same data as above
Lets look at this data:
const manySeriesData = [{"category": "Lithuania","value": 501.9,"marketing": 250,"sales": 199}, {"category": "Czech Republic","value": 301.9,"marketing": 222,"sales": 251}, {"category": "Ireland","value": 201.1,"marketing": 170,"sales": 199}, {"category": "Germany","value": 165.8,"marketing": 122,"sales": 90}, {"category": "Australia","value": 139.9,"marketing": 99,"sales": 252}];
To add many series to the pie chart you will have to give series param and array of series
type
PieChart3D
PieChart
PieChart
Select the series type
legend
Object
Boolean
false
Value that shows a Chart Legend
radiusInside
Number
30
Size of the inner Circle
series
object
array>objects
Customize and add series
type
PieSeries3D
PieSeries
PieSeries
Select the series type
value
String
category
value name param from data
category
String
value
category name param from data
name
String
Series Title
fill
arm4 Color
Get color from data or use the default color palette from amchart
Change the serie color
stroke
arm4 Color
Change the stroke color
strokeWidth
number
1
Change Stroke Width
strokeOpacity
number
1
Change Stroke Opacity
disabledTooltip
Boolean
false
Disabled tooltip
tooltipText
String
{valueY.value}
Text of the tooltip
disabledLabel
Boolean
false
Remove Series labels
disabledTick
Boolean
false
Remove Series Ticks
scale
Number
The scale animation on hover less than 1 will be animated to the innerCircle and more than 1 will be animated going away the circle
PieSeries3D
Show a 3d circle graph
PieSeries
Show a circle graph