这是一个基于 Next.js 构建的智能数据可视化系统。
本项目是一个智能化的数据可视化系统,能够根据数据特征和用户需求自动生成最适合的图表展示。系统支持多种图表类型,并提供了灵活的配置选项和交互功能。
- 前端框架: Next.js 13+
- UI 库: Ant Design
- 图表库: ECharts
- 开发语言: TypeScript
- 样式方案: Tailwind CSS
class ChartHandlerRegistry {
private static instance: ChartHandlerRegistry;
private handlers = new Map<ChartType, ChartTypeHandler>();
// 提供注册和获取处理器的方法
register(type: ChartType, handler: ChartTypeHandler): void
getHandler(type: ChartType): ChartTypeHandler | undefined
getImplementedTypes(): ChartType[]
}abstract class BaseChartHandler {
// 提供通用的图表配置方法
protected getDefaultTooltip()
protected getDefaultGrid()
protected getDefaultLegend()
protected formatValue()
protected getColorPalette()
}export const CHART_TYPES = ['bar', 'line', 'pie', ...] as const;
export type ChartType = typeof CHART_TYPES[number];interface ChartTypeHandler {
validateData(data: any[]): ValidationResult;
preProcess(data: any[]): ProcessedData;
getEncode(dimensions: string[]): Record<string, any>;
getSeriesConfig(processedData: ProcessedData): any;
getSpecialConfig?(processedData: ProcessedData): any;
}- 原始数据输入
- 数据验证
- 数据预处理
- 生成基础配置
- 生成系列配置
- 生成特殊配置
- 输出最终图表配置
class ChartError extends Error {
constructor(
message: string,
public chartType: ChartType,
public errorType: 'validation' | 'processing' | 'rendering'
)
}- 实现新的 Handler 类
- 在注册表中注册
- 更新类型定义
- 添加图表配置
- 基础配置在 BaseHandler 中
- 特殊配置在具体 Handler 中
支持中英文的错误消息和提示:
const messages = {
validation: {
cn: '数据验证失败',
en: 'Data validation failed'
}
// ...
}# 安装依赖
pnpm install
# 启动开发服务器
pnpm dev
# 构建生产版本
pnpm build- 在
src/components/charts/handlers/implementations创建新的处理器文件 - 实现
ChartTypeHandler接口 - 在
src/components/charts/handlers/index.ts注册新处理器 - 更新
src/components/charts/types/chartTypes.ts中的类型定义
- 继承
BaseChartHandler - 重写需要自定义的方法
- 实现特殊配置方法
getSpecialConfig
src/
├── components/
│ └── charts/
│ ├── handlers/ # 图表处理器
│ ├── types/ # 类型定义
│ └── controls/ # 图表控制组件
├── utils/
│ └── pipelines/ # 数据处理管道
└── locales/ # 国际化资源
- 所有的图表处理器必须实现
ChartTypeHandler接口 - 确保在添加新图表类型时更新类型定义
- 保持错误处理的一致性
- 注意配置的类型安全
- Fork 本仓库
- 创建特性分支
- 提交更改
- 发起 Pull Request
This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.js. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Geist, a new font family for Vercel.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.