图表组件封装

This commit is contained in:
mmc
2026-05-14 13:30:29 +08:00
parent 4e5a4fb241
commit abe5631642
3 changed files with 165 additions and 97 deletions

View File

@@ -15,26 +15,6 @@ import {
Bar,
} from 'recharts';
// =========================
// 通用类型定义
// =========================
export interface SeriesConfig {
key: string;
name: string;
color?: string;
strokeWidth?: number;
}
export interface BaseChartProps {
width?: number | string;
height?: number;
showGrid?: boolean;
showLegend?: boolean;
showTooltip?: boolean;
backgroundColor?: string;
className?: string;
}
// 默认颜色池
const DEFAULT_COLORS = [
@@ -48,21 +28,9 @@ const DEFAULT_COLORS = [
'#2f54eb',
];
// =========================
// 折线图组件
// =========================
export interface UniversalLineChartProps extends BaseChartProps {
data: Record<string, any>[];
xKey: string;
series: SeriesConfig[];
smooth?: boolean;
dot?: boolean;
xAxisLabel?: string;
yAxisLabel?: string;
}
export const UniversalLineChart: React.FC<UniversalLineChartProps> = ({
export const UniversalLineChart = ({
data,
xKey,
series,
@@ -117,20 +85,9 @@ export const UniversalLineChart: React.FC<UniversalLineChartProps> = ({
);
};
// =========================
// 柱状图组件
// =========================
export interface UniversalBarChartProps extends BaseChartProps {
data: Record<string, any>[];
xKey: string;
series: SeriesConfig[];
barSize?: number;
radius?: number | [number, number, number, number];
stack?: boolean;
}
export const UniversalBarChart: React.FC<UniversalBarChartProps> = ({
export const UniversalBarChart = ({
data,
xKey,
series,
@@ -185,25 +142,9 @@ export const UniversalBarChart: React.FC<UniversalBarChartProps> = ({
);
};
// =========================
// 饼图组件
// =========================
export interface PieDataItem {
name: string;
value: number;
color?: string;
}
export interface UniversalPieChartProps extends BaseChartProps {
data: PieDataItem[];
innerRadius?: number;
outerRadius?: number;
paddingAngle?: number;
showLabel?: boolean;
}
export const UniversalPieChart: React.FC<UniversalPieChartProps> = ({
export const UniversalPieChart = ({
data,
width = '100%',
height = 360,