Intervals
The Intervals feature provides comprehensive timeframe management for the financial charting library. This system enables users to change the chart's resolution and timeframe, supporting various aggregation periods from tick data to monthly charts.
Key Features
- Timeframe switching (1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w, 1M)
- Tick-based charting support
- Custom interval configuration
- Interval validation and normalization
- Real-time interval updates
- Historical data loading based on selected interval
Architecture / Behavior
The intervals system follows a layered architecture:
- UI Layer: Top toolbar timeframe selector with dropdown menu
- API Layer: ChartApi and GlobalApi interval methods
- State Layer: ChartStore manages current interval state
- Data Layer: Data feed handles historical data requests based on interval
The interval flow: UI → ChartApi → ChartStore → DataFeed → Backend API → Response → ChartStore → UI.
API Usage
Initialization
The intervals feature is enabled by default in the chart configuration:
const chart = Chart.create(document.getElementById('container'), {
// ... other options
interval: '1D', // Default interval
enabled_features: ['interval'], // Enable interval functionality
});
Methods
ChartApi.setInterval() - Set the chart interval:
// Set interval to 1 minute
await chart.getApi().setInterval('1');
// Set interval to daily
await chart.getApi().setInterval('1D');
// Set interval to weekly
await chart.getApi().setInterval('1W');
ChartApi.getInterval() - Get the current chart interval:
const currentInterval = chart.getApi().getInterval();
console.log(`Current interval: ${currentInterval}`);
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
interval | string | '1D' | Default chart interval |
enabled_features | string[] | ['interval'] | Enable/disable interval functionality |
enabled_resolution | string[] | ['1', '5', '15', '30', '60', '1D', '1W'] | List of enabled resolutions |
disabled_resolution | string[] | [] | List of disabled resolutions |
Events
interval:changed- Fired when interval changes
Customization
- UI styling can be customized via CSS classes
- Available intervals can be customized through configuration
- Interval display format can be customized using locale settings
Use Cases
- Switching between intraday and daily timeframes
- Analyzing different market cycles
- Building multi-timeframe analysis systems
- Creating custom timeframe indicators
- Integration with trading strategies
Limitations
- Requires data feed implementation of
getBars()method - Performance depends on backend API response times
- Some intervals may not be supported by all data feeds
- Limited to intervals supported by connected data feeds
✅ Supported
- Interval switching API methods
- Interval state management
- Real-time interval updates
- Historical data loading
Feature Classification
Core Feature - Fundamental functionality required for basic chart operation
Dependencies
- Requires backend? Yes (data feed API)
- Requires storage? No
- Requires real-time data? Yes (for live updates)
- Requires UI controls? Yes (timeframe selector)
Missing Implementation Analysis
The intervals functionality is fully implemented and production-ready. All core interval capabilities are present in the codebase with proper error handling and validation mechanisms.
Consistency Validation
The intervals API follows the same pattern as other API methods with consistent promise-based return values and error handling. Naming conventions are consistent with other features.
UI vs API Separation
- UI handles: Timeframe selector, dropdown menu, visual feedback
- API exposes:
setInterval(),getInterval(),getAvailableIntervals()methods - Must implement manually: Custom data feed interval support
User Flow
- User selects interval from dropdown
- ChartApi validates interval
- ChartStore updates state
- DataFeed requests historical data
- Chart renders new timeframe
- UI updates visual indicator
Integration with Existing Docs
This feature should be linked from:
- Charting section → Top Toolbar
- API Reference → ChartApi
- Connecting Data → Data Feeds
- Getting Started → Quick Start Guide