Overview
MicroCBM provides three chart components built on the Recharts library for visualizing maintenance data, trends, and analytics:- AreaChart - Time series data with filled areas
- BarChart - Comparative metrics visualization
- PieChart - Proportional data display with legend
AreaChart
Line chart with gradient-filled areas for displaying time series data like oil sample measurements over time.Props
Array of data points with structure:
{ date: string, series1: number, series2: number }Additional CSS classes for the chart container
Data Structure
Usage Example
src/app/(home)/samples/components/TrendChart.tsx
Features
- Gradient fills for visual appeal
- Automatic date formatting on X-axis
- PPM (parts per million) units on Y-axis
- Interactive tooltips with hover states
- Responsive container sizing
- Smooth curve transitions
Customization
The AreaChart uses predefined gradient colors:- Series 1: Gray gradient (
#A0A0A0) - Series 2: Light gray gradient (
#D0D0D0)
The Y-axis domain is fixed at [0, 30] PPM. To customize the range, modify the
domain prop in the source component.BarChart
Bar chart component for comparing metrics across time periods or categories.Props
Array of data points with structure:
{ month: string, value1: number, value2?: number }Chart title displayed at the top
Subtitle or description text
Label for the first data series in tooltips
Label for the second data series in tooltips
Additional CSS classes for the chart container
Optional filter tabs for time range selection
Callback when time filter is changed
Currently selected time filter value
Data Structure
Usage Example
Features
- Automatic month name formatting (“2025-01” → “Jan”)
- Dynamic Y-axis scaling based on data
- Grouped bars for comparing two series
- Interactive tooltips with data labels
- Optional time filter controls
- Border and padding styling
Styling
- Bar Colors: Black (
#000) for value1, dark gray (#333) for value2 - Bar Width: Fixed at 20px
- Height: 320px (80 in Tailwind units)
- Grid: Horizontal lines with 3-3 dash pattern
If your data contains only
value1, the second bar series will not render. The chart automatically detects and handles single-series data.PieChart
Donut chart component for displaying proportional data with a center label and legend.Props
Array of data segments with structure:
{ name: string, value: number, color: string }Chart title
Subtitle text
Value displayed in the center of the donut
Label text for the center value
Additional CSS classes
Data Structure
Usage Example
src/app/(home)/samples/components/SampleStatusChart.tsx
Features
- Donut chart with center content area
- Custom color per segment
- Interactive hover tooltips with percentages
- Legend with color indicators
- Export button (UI only, implement handler separately)
- Date picker integration
- Responsive sizing
Layout
The PieChart component includes:- Header Section - Title, subtitle, export button, and date picker
- Chart Section - Donut chart with center value/label (256x256px)
- Legend Section - Horizontal legend with color swatches
Customization
The tooltip shows both absolute values and percentages. Percentages are calculated automatically from the data.
Common Patterns
Loading States
Handle loading states while fetching chart data:Empty States
Display appropriate messages when no data is available:Responsive Layouts
Use grid layouts to arrange multiple charts:Recharts Integration
All chart components use Recharts internally. Key Recharts components used:ResponsiveContainer- Automatic resizingCartesianGrid- Grid linesXAxis/YAxis- Axis configurationTooltip- Interactive hover tooltipsArea/Bar/Pie- Chart renderers
Performance Considerations
- Charts are client-side only (use
"use client"directive) - Large datasets may impact performance
- Consider data aggregation for datasets over 100 points
- Use React.memo() for charts that re-render frequently
Styling Guidelines
Colors
Use consistent color schemes across charts:Typography
Chart text uses these font sizes:- Title:
text-lg(18px) withfont-semibold - Subtitle:
text-sm(14px) withtext-gray-500 - Axis Labels: 12px font size
- Tooltips:
text-xs(12px)
Accessibility
- All charts include proper ARIA labels via Recharts
- Tooltips provide text alternatives for visual data
- Color is not the only means of conveying information (labels included)
- Consider providing data tables as alternatives for screen readers
Next Steps
- UI Components - Buttons, inputs, and more
- Form Inputs - Specialized form components
- Development Guide - Component architecture