SentimentChart component visualizes sentiment trends over time using Recharts. It displays positive, negative, and neutral sentiment scores with configurable time ranges from 6 hours to 7 days.
Usage
Features
- Multiple time ranges: 6H, 12H, 24H, 3D, 7D
- Three sentiment lines: Positive (green), Negative (red), Neutral (gray)
- Volume indicator: Shows post volume in tooltip
- Live data integration: Uses
useSentimentTimeline()hook with fallback to mock data - Dark mode support: Automatically adapts colors based on theme
- Responsive design: Fluid width and height adjustment
Data Structure
The chart expects data in the following format:Time Ranges
Available time range options:| Label | Hours | Data Points | Typical Use Case |
|---|---|---|---|
| 6H | 6 | 12 | Real-time monitoring |
| 12H | 12 | 24 | Short-term trends |
| 24H | 24 | 24 | Daily overview (default) |
| 3D | 72 | 36 | Multi-day analysis |
| 7D | 168 | 42 | Weekly trends |
Implementation Details
State Management
Data Source Priority
- Live data: If
useSentimentTimeline()returns data from the database - Mock data: Generated via
generateTrendData()if no live data available
Custom Tooltip
The tooltip displays:- Time label: Formatted timestamp
- Color indicators: Matching the line colors
- Sentiment values: Positive, negative, neutral scores
- Volume: Total posts (if available)
Color Scheme
Light Mode
- Positive:
hsl(142, 76%, 36%)(emerald-600) - Negative:
hsl(0, 84%, 60%)(red-500) - Neutral:
hsl(220, 9%, 46%)(gray-500) - Grid:
hsl(220, 14%, 87%)
Dark Mode
- Positive:
hsl(142, 71%, 45%)(emerald-500) - Negative:
hsl(0, 72%, 51%)(red-600) - Neutral:
hsl(220, 9%, 46%) - Grid:
hsl(222, 12%, 22%)
Chart Configuration
Integration with Database
The component uses theuseSentimentTimeline() hook to fetch live data:
Performance Optimization
Accessibility
- Color-blind friendly: Uses distinct line styles and gradients
- Keyboard navigation: Clickable time range buttons
- Screen reader: Chart data accessible via tooltip
Related Components
SentimentGauge
Current sentiment score visualization
EmotionBreakdown
Six-emotion distribution bars
TopicDetail
Main analysis container