Spaces:
Sleeping
Sleeping
File size: 1,200 Bytes
645ad9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import { Bar, Pie, Line } from 'react-chartjs-2';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
BarElement,
LineElement,
PointElement,
ArcElement,
Title,
Tooltip,
Legend
} from 'chart.js';
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
LineElement,
PointElement,
ArcElement,
Title,
Tooltip,
Legend
);
interface AIVisualizationProps {
visualization: {
type: 'bar' | 'pie' | 'line' | 'doughnut';
config: any;
};
}
export default function AIVisualization({ visualization }: AIVisualizationProps) {
const ChartComponent = {
bar: Bar,
pie: Pie,
line: Line,
doughnut: Pie
}[visualization.type];
if (!ChartComponent) return null;
const options = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top' as const,
},
title: {
display: true,
text: 'Data Visualization'
}
},
...(visualization.type === 'doughnut' && {
cutout: '50%'
})
};
return (
<div className="w-full h-[400px]">
<ChartComponent
data={visualization.config}
options={options}
/>
</div>
);
} |