const { useRef, useEffect } = React;
const data = [
{ category: '전자기기', sales: 2810, revenue: 296700000 },
{ category: '액세서리', sales: 9640, revenue: 99300000 },
{ category: '웨어러블', sales: 1100, revenue: 55000000 },
{ category: '주변기기', sales: 450, revenue: 67500000 },
];
const PALETTE = ['#007AFF', '#34C759', '#FF9500', '#AF52DE'];
function App() {
const gridHost = useRef(null);
const chartHost = useRef(null);
const pieHost = useRef(null);
const totalRevenue = data.reduce((sum, d) => sum + d.revenue, 0);
const totalSales = data.reduce((sum, d) => sum + d.sales, 0);
const topCategory = data.reduce((a, b) => (a.revenue > b.revenue ? a : b)).category;
useEffect(() => {
const grid = new wijmo.grid.FlexGrid(gridHost.current, {
autoGenerateColumns: false,
columns: [
{ binding: 'category', header: '카테고리', width: 100 },
{ binding: 'sales', header: '판매량', width: '*', minWidth: 80, format: 'n0' },
{ binding: 'revenue', header: '매출액(원)', width: '*', minWidth: 120, format: 'n0' },
],
itemsSource: data,
});
const chart = new wijmo.chart.FlexChart(chartHost.current, {
itemsSource: data,
bindingX: 'category',
chartType: 'Column',
header: '카테고리별 매출',
series: [{ name: '매출액', binding: 'revenue' }],
palette: PALETTE,
legend: { position: 'None' },
});
const pie = new wijmo.chart.FlexPie(pieHost.current, {
itemsSource: data,
binding: 'revenue',
bindingName: 'category',
header: '매출 비중',
innerRadius: 0.6,
palette: PALETTE,
legend: { position: 'Right' },
});
return () => {
grid.dispose();
chart.dispose();
pie.dispose();
};
}, []);
return (
<div style={{ fontFamily: "-apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Pretendard, sans-serif" }}>
<p style={{ marginBottom: 12, color: '#555', fontSize: 13 }}>
같은 데이터 배열을 그리드·차트·도넛에 각각 전달했을 뿐, 별도 동기화 코드는 없습니다.
</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, marginBottom: 16 }}>
<div className="ios-stat-card">
<div className="ios-stat-label">총 매출액</div>
<div className="ios-stat-value">₩{(totalRevenue / 100000000).toFixed(1)}억</div>
</div>
<div className="ios-stat-card">
<div className="ios-stat-label">총 판매량</div>
<div className="ios-stat-value">{totalSales.toLocaleString()}개</div>
</div>
<div className="ios-stat-card">
<div className="ios-stat-label">최고 매출 카테고리</div>
<div className="ios-stat-value" style={{ fontSize: 20 }}>{topCategory}</div>
</div>
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 16 }}>
<div ref={gridHost} className="ios-dash-card" style={{ flex: '1 1 220px', height: 240 }} />
<div ref={chartHost} className="ios-dash-card" style={{ flex: '1 1 220px', height: 240 }} />
<div ref={pieHost} className="ios-dash-card" style={{ flex: '1 1 220px', height: 240 }} />
</div>
</div>
);
}
ReactDOM.createRoot(document.getElementById('root')).render(<App />);