-
Notifications
You must be signed in to change notification settings - Fork 2k
/
pie-chart.tsx
49 lines (45 loc) · 1.2 KB
/
pie-chart.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Datum, PieConfig } from '@ant-design/charts';
import { sum } from 'lodash';
import dynamic from 'next/dynamic';
export type PieChartData = {
type: string;
value: number;
};
interface PieChartProps {
title: string;
data: Array<PieChartData>;
color: (type: string) => string;
}
const DynamicPie = dynamic(() => import('@ant-design/plots').then((item) => item.Pie), {
ssr: false
});
export const PieChart = ({ title, data, color }: PieChartProps) => {
const config: PieConfig = {
data: data,
angleField: 'value',
colorField: 'type',
color: (datum: Datum) => color(datum['type']),
width: 200,
radius: 1,
innerRadius: 0.75,
statistic: {
title: false,
content: {
customHtml: () => {
return (
<div>
<div className="font-medium text-base text-black">{title}</div>
<div className="font-medium text-4xl text-black">{sum(data.map((d) => d.value))}</div>
</div>
) as unknown as string;
}
}
},
label: false,
legend: {
layout: 'vertical' as 'vertical',
position: 'bottom' as 'bottom'
}
};
return <DynamicPie {...config} animation={false} />;
};