"use client"; import { GeoData } from '@/app/api/types'; interface GeoAnalyticsProps { data: GeoData[]; } export default function GeoAnalytics({ data }: GeoAnalyticsProps) { // 安全地格式化数字 const formatNumber = (value: number | undefined | null): string => { if (value === undefined || value === null) return '0'; return value.toLocaleString(); }; // 安全地格式化百分比 const formatPercent = (value: number | undefined | null): string => { if (value === undefined || value === null) return '0'; return value.toFixed(1); }; const sortedData = [...data].sort((a, b) => (b.visits || 0) - (a.visits || 0)); return (
{sortedData.map((item, index) => ( ))}
Location Visits Unique Visitors % of Total
{item.location || 'Unknown'} {formatNumber(item.visits)} {formatNumber(item.visitors)}
{formatPercent(item.percentage)}%
); }