Pie Chart
Basic Pie Chart
Let's start by building a basic pie chart that displays the flight data.
export default function PieChart(): ReactElement {
// roll up data by month
const options: AgChartOptions = useMemo(
() => ({
data,
series: [
{
type: 'pie',
angleKey: 'time',
},
],
}),
[]
);
return <AgCharts options={options} />;
}
- The series type is set to
pieto render a pie chart. - The
angleKeyproperty maps the data to the chart.
Labels
The calloutLabelKey property is used to display the label of the pie chart slice.
And, the legendItemKey property is used to display the legend label.
export function PieChart(): ReactElement {
// roll up data by month
const options: AgChartOptions = useMemo(
() => ({
data,
series: [
{
type: 'pie',
angleKey: 'time',
legendItemKey: 'label',
calloutLabelKey: 'label',
},
],
theme,
}),
[data]
);
return <AgCharts options={options} />;
}
Challenge
Open the Challenge on Stackblitz
For this challenge, you will update the pie chart to display the total flight time per month, using the provided dataset. Here’s what you need to do:
- Create a series of type
'pie':- Set the
angleKeyto'time'(this will represent the flight time for each slice). - Set the
legendItemKeyto'label'. - Set the
calloutLabelKeyto'label'.
- Set the