line-chart.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 LineChart({ chart }: { 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: 'view',
  19. data: chart.values,
  20. children: [
  21. {
  22. type: 'line',
  23. encode: {
  24. x: 'name',
  25. y: 'value',
  26. color: 'type',
  27. shape: 'smooth',
  28. },
  29. },
  30. {
  31. type: 'area',
  32. encode: {
  33. x: 'name',
  34. y: 'value',
  35. color: 'type',
  36. shape: 'smooth',
  37. },
  38. legend: false,
  39. style: {
  40. fillOpacity: 0.15,
  41. },
  42. },
  43. ],
  44. axis: {
  45. x: {
  46. labelAutoRotate: false,
  47. },
  48. },
  49. }}
  50. />
  51. </div>
  52. </div>
  53. </div>
  54. );
  55. }