Trend Comparison is an analytics widget that overlays two data series on a single chart with an integrated legend and period toggle. It enables side-by-side comparison of metrics (e.g., this month vs. last month, plan A vs. plan B) within a single, self-contained card. The widget builds on the existing line and area chart primitives in charts.tsx.
Goals
Provide a <TrendComparison> component that renders two series on one chart with distinct visual treatments.
Include a built-in legend identifying each series by name and color.
Include a period toggle for switching comparison windows.
More than two series in a single comparison (deferred to a multi-series chart widget).
Drill-down or click-to-filter interactions on data points.
Statistical analysis (correlation, regression) computed within the component.
Server-side data fetching or query integration.
Scope
In Scope
Area
Description
Component
<TrendComparison> widget rendering two overlaid series
Legend
Color-coded legend with series names, toggleable visibility
Period Toggle
Segmented control for switching comparison time ranges
Visual Differentiation
Primary series as solid line/area, comparison series as dashed line or lower-opacity area
States
Loading skeleton, empty state, error state
Stories
Storybook stories for line overlay, area overlay, period switching, and edge cases
Out of Scope
Area
Reason
Three or more series
Separate multi-series component; two-series keeps the UX focused
Bar chart comparison
Grouped/stacked bar is a different layout pattern
Data normalization
Consumer is responsible for aligning series to the same x-axis
Annotations or markers
Future enhancement, not part of initial comparison widget
Users and Pain Points
User Groups
User
Description
Needs
Developers
Engineers building analytics dashboards
A ready-made two-series comparison widget
Designers
Design-system consumers
Consistent dual-series visual treatment
Analysts
Dashboard end users
Quick visual comparison of two time periods or segments
Pain Points
User
Pain Point
Impact
Developers
Building dual-series overlays requires manual z-index management, duplicate chart instances, and custom legend wiring
Slow development, inconsistent results
Analysts
Comparing metrics requires opening two separate cards side-by-side
Harder to spot trends and correlations
Definitions
Term
Definition
Series
A named sequence of data points rendered as a single line or area on the chart
Primary Series
The main metric being examined; rendered with the primary color token
Comparison Series
The secondary metric or time-shifted variant; rendered with a muted or dashed treatment
Period Toggle
A control that switches which time window both series display
Current State
Existing Behavior
The design system provides single-series line and area charts in charts.tsx. There is no built-in support for rendering two series on a shared axis. MetricCard supports a single sparkline but not a dual-series comparison.
Current Limitations
Charts accept a single data: ChartDataPoint[] array with no multi-series concept.
No legend component exists for chart series identification.
No pattern for visually differentiating a primary vs. comparison series.
Existing Workarounds
Developers render two separate chart cards and ask users to compare visually.
Some teams overlay two absolute-positioned chart components, which is fragile and inaccessible.
Proposed Solution
Summary
Introduce <TrendComparison> that accepts primarySeries and comparisonSeries props, each containing a name, color token, and data array. The component renders both series on a shared axis using the existing chart rendering logic, adds a legend, and includes an optional period toggle.
Key Capabilities
Dual-series overlay on a single chart with shared x-axis and y-axis.
Built-in legend with series name, color swatch, and toggle to hide/show each series.
Period toggle for time range switching.
Visual differentiation: solid vs. dashed line, or full-opacity vs. reduced-opacity area.
User Experience
Users see a chart card with two overlaid lines or areas. A legend below the chart identifies each series. A period toggle in the header switches the time window. Hovering shows a tooltip with values from both series at the hovered x-position.