Donut.tsx
1.73 KB
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
50
51
52
53
import { dist } from '../tools/data';
export function Donut() {
const total = dist.reduce((s, d) => s + d.value, 0);
const r = 52;
const c = 2 * Math.PI * r;
let offset = 0;
const circles = dist.map((d) => {
const len = (d.value / total) * c;
const el = (
<circle
key={d.label}
cx={66}
cy={66}
r={r}
fill="none"
stroke={d.color}
strokeWidth="14"
strokeDasharray={`${len} ${c - len}`}
strokeDashoffset={-offset}
transform="rotate(-90 66 66)"
/>
);
offset += len;
return el;
});
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<svg width={132} height={132} viewBox="0 0 132 132">
<circle cx={66} cy={66} r={r} fill="none" stroke="#F0F2F7" strokeWidth="14" />
{circles}
<text x={66} y={62} fontSize="22" fontWeight={700} fill="#1D2533" textAnchor="middle">
{total}
</text>
<text x={66} y={80} fontSize="11" fill="#8A94A6" textAnchor="middle">
门店总数
</text>
</svg>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{dist.map((d) => (
<div key={d.label} style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<span style={{ width: 9, height: 9, borderRadius: 3, background: d.color }} />
<span style={{ fontSize: 13, color: '#4A5568', minWidth: 72 }}>{d.label}</span>
<span style={{ fontSize: 13, fontWeight: 600, color: '#1D2533' }}>{d.value}</span>
<span style={{ fontSize: 12, color: '#AAB3C2' }}>
{Math.round((d.value / total) * 100)}%
</span>
</div>
))}
</div>
</div>
);
}