import React from 'react'; import { ResponsiveContainer, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, PieChart, Pie, Cell, BarChart, Bar, } from 'recharts'; // 默认颜色池 const DEFAULT_COLORS = [ '#1677ff', '#52c41a', '#fa8c16', '#eb2f96', '#722ed1', '#13c2c2', '#f5222d', '#2f54eb', ]; export const UniversalLineChart = ({ data, xKey, series, width = '100%', height = 360, showGrid = true, showLegend = true, showTooltip = true, backgroundColor = '#ffffff', smooth = true, dot = false, className, }) => { return (
{showGrid && ( )} {showTooltip && } {showLegend && } {series.map((item, index) => ( ))}
); }; export const UniversalBarChart = ({ data, xKey, series, width = '100%', height = 360, showGrid = true, showLegend = true, showTooltip = true, backgroundColor = '#ffffff', barSize = 28, radius = 6, stack = false, className, }) => { return (
{showGrid && ( )} {showTooltip && } {showLegend && } {series.map((item, index) => ( ))}
); }; export const UniversalPieChart = ({ data, width = '100%', height = 360, showLegend = true, showTooltip = true, backgroundColor = '#ffffff', innerRadius = 40, outerRadius = 60, paddingAngle = 2, showLabel = true, className, style }) => { return (
{showTooltip && } {showLegend && } {data.map((entry, index) => ( ))}
); }; // ========================= // 使用示例 // ========================= export const DemoCharts = () => { const lineData = [ { month: '1月', uv: 400, pv: 240, amt: 240 }, { month: '2月', uv: 300, pv: 456, amt: 300 }, { month: '3月', uv: 500, pv: 139, amt: 200 }, { month: '4月', uv: 278, pv: 390, amt: 278 }, { month: '5月', uv: 189, pv: 480, amt: 189 }, ]; const pieData = [ { name: 'Vue', value: 40 }, { name: 'React', value: 35 }, { name: 'Angular', value: 25 }, ]; return (
); };