This Angular application allows users to search for stocks, view detailed information, and visualize historical price data using interactive charts. The app integrates with external APIs to fetch stock details and time series data (monthly, weekly, daily).
- API Response Handling: The app handles multiple API response formats (e.g., search results vs. global quote) using type guards and conditional rendering. This ensures robustness when the API returns different structures.
- Chart Rendering: Chart.js is used for data visualization. To avoid errors with multiple charts, each chart uses a unique canvas ID, and previous chart instances are destroyed before creating new ones.
- Error Handling: All API calls include error handling to display errors in the console and prevent UI crashes. The app checks for missing or malformed data before rendering components.
- Responsive Design: The charts container uses CSS Grid for a responsive layout, ensuring charts display well on various screen sizes.
- Performance: RxJS operators like
debounceTimeanddistinctUntilChangedare used to optimize search input and reduce unnecessary API calls.
- Angular v15
- RxJS for reactive programming and API call management
- Chart.js for data visualization
- TypeScript for type safety and maintainability
- SCSS for styling and responsive design
- Type a stock symbol in the search box to get suggestions.
- Select a suggestion to view detailed stock info and historical charts.
- The app displays monthly, weekly, and daily time series data in separate charts.
- If the API returns an unexpected format, the app will not crash and will log a warning.
- If a user selects a new stock, all charts and details update accordingly.
- If a chart is re-rendered, the previous instance is destroyed to avoid Chart.js canvas errors.
src/app/app.component.ts– Main logic for search, selection, and API callssrc/app/app.component.html– Main template, including charts and detailssrc/app/@components/stock-chart/stock-chart.component.ts– Chart rendering logicsrc/app/@components/stock-details/stock-details.component.ts– Stock details display
- Add user-friendly error messages in the UI
- Implement loading indicators for API calls