bar-chart.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { ChatContext } from '@/app/chat-context';
  2. import { ChartData } from '@/types/chat';
  3. import { Chart } from '@berryv/g2-react';
  4. import { useContext } from 'react';
  5. export default function BarChart({ chart }: { key: string; chart: ChartData }) {
  6. const { mode } = useContext(ChatContext);
  7. return (
  8. <div className='flex-1 min-w-0 p-4 bg-white dark:bg-theme-dark-container rounded'>
  9. <div className='h-full'>
  10. <div className='mb-2'>{chart.chart_name}</div>
  11. <div className='opacity-80 text-sm mb-2'>{chart.chart_desc}</div>
  12. <div className='h-[300px]'>
  13. <Chart
  14. style={{ height: '100%' }}
  15. options={{
  16. autoFit: true,
  17. theme: mode,
  18. type: 'interval',
  19. data: chart.values,
  20. encode: { x: 'name', y: 'value', color: 'type' },
  21. axis: {
  22. x: {
  23. labelAutoRotate: false,
  24. },
  25. },
  26. }}
  27. />
  28. </div>
  29. </div>
  30. </div>
  31. );
  32. }