Files
DataClaw/frontend/src/components/VegaChart.tsx
T

30 lines
759 B
TypeScript
Raw Normal View History

2026-03-15 01:29:36 +08:00
import React from 'react';
import { VegaEmbed } from 'react-vega';
import type { ChartSpec } from '@/store/visualizationStore';
interface VegaChartProps {
data: any[];
spec: ChartSpec;
}
export const VegaChart: React.FC<VegaChartProps> = ({ data, spec }) => {
const vegaSpec: any = {
2026-03-15 10:49:37 +08:00
$schema: typeof spec.$schema === 'string' ? spec.$schema : 'https://vega.github.io/schema/vega-lite/v5.json',
...spec,
2026-03-15 01:29:36 +08:00
width: "container",
height: "container",
2026-03-15 10:49:37 +08:00
data: { values: data },
autosize: { type: "fit", contains: "padding" },
2026-03-15 01:29:36 +08:00
};
return (
<div className="w-full h-full">
<VegaEmbed
spec={vegaSpec}
options={{ actions: false }}
style={{width: '100%', height: '100%'}}
/>
</div>
);
};