import { ChatContext } from '@/app/chat-context'; import { ChartData } from '@/types/chat'; import { Chart } from '@berryv/g2-react'; import { useContext, useMemo } from 'react'; export default function BarChart({ chart }: { key: string; chart: ChartData }) { const { mode } = useContext(ChatContext); // Process data to ensure numeric values for proper y-axis ordering const processedChart = useMemo(() => { const processedValues = chart.values .map(item => ({ ...item, value: typeof item.value === 'string' ? parseFloat(item.value) || 0 : item.value, })) // Sort by value in descending order for better visualization .sort((a, b) => b.value - a.value); return { ...chart, values: processedValues, }; }, [chart]); // Smart number formatter: show integers as integers, decimals with 2 decimal places const formatNumber = (value: any) => { const num = Number(value); return Number.isInteger(num) ? num.toString() : num.toFixed(2); }; return (
{chart.chart_name}
{chart.chart_desc}
); }