Description
Charts API Endpoints
The Charts module provides a universal chart generation system that converts flexible query parameters into SQL queries and returns data formatted for Nivo charts.
Line Chart
GET /v1/charts/line
Generate line chart data based on flexible query parameters. The system automatically converts the request into appropriate SQL queries and returns data formatted for Nivo line charts.
Core Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
rec_type | string | ✅ | Record type to query | currency_pairs |
x_field | string | ✅ | Field to use for X-axis values | date, base_currency |
y_field | string | ✅ | Field to use for Y-axis values | rate |
Data Control Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
group_by | string | ❌ | Field to group by for multiple series | base_currency, type, source |
limit | integer | ❌ | Limit number of data points (1-1000) | 100 |
offset | integer | ❌ | Offset for pagination | 0 |
fill_gaps | string | ❌ | Gap filling strategy: "no", "daily", "monthly" | daily |
Chart Styling Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
color | string | ❌ | Base color for chart series (HSL) | hsl(58, 70%, 50%) |
Filter Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
search.base_currency | string | ❌ | Filter by base currency | USD, EUR, CHF |
search.target_currency | string | ❌ | Filter by target currency | USD, EUR, CHF |
search.type | string | ❌ | Filter by type | MID, BID, ASK, SELL, BUY |
search.source | string | ❌ | Filter by source | SNB, Currency Cloud |
search.date.gte | string | ❌ | Filter by date greater than or equal to (RFC3339) | 2024-01-01T00:00:00Z |
search.date.lte | string | ❌ | Filter by date less than or equal to (RFC3339) | 2024-12-31T23:59:59Z |
Supported Record Types
Currency Pairs
- Table:
currencies.currency_pairs - X-Field Options:
date,base_currency,target_currency,type,source - Y-Field Options:
rate - Group By Options:
base_currency,target_currency,type,source - Available Fields:
date,base_currency,target_currency,type,source,rate
Gap Filling Strategies
The fill_gaps parameter allows you to fill missing time points in your chart data with null values, ensuring a complete timeline for better visualization.
Available Strategies
| Strategy | Description | Use Case |
|---|---|---|
no | No gap filling (default) | When you want only actual data points |
daily | Fill gaps with daily intervals | For daily time series data |
monthly | Fill gaps with monthly intervals | For monthly aggregated data |
How It Works
- Date Range Detection: The system uses search parameters (
search.date.gteandsearch.date.lte) to determine the full date range - Gap Identification: Compares existing data points against the complete date range
- Zero Value Insertion: Inserts data points with
y: 0for missing dates - Complete Timeline: Returns a consistent timeline regardless of data availability
Example Scenarios
Daily Gap Filling: When you have data for July 1st, 3rd, and 5th, but want to show all 31 days of July:
fill_gaps=dailywill create 31 data points- Days 2, 4, 6-30 will have
y: 0 - Days 1, 3, 5 will have actual values
Monthly Gap Filling: When you have data for January, March, and December, but want to show all 12 months:
fill_gaps=monthlywill create 12 data points- February, April-November will have
y: null - January, March, December will have actual values
Chart Features
Multi-Series Support
When using group_by, the API returns multiple series, each with a unique color generated from the base color.
Dynamic Color Generation
Colors are automatically generated for multiple series using HSL color space variations.
Pagination Support
Use limit and offset parameters for handling large datasets.
Usage Examples
Basic Exchange Rate Chart
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&limit=50"Multi-Currency Chart
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&group_by=base_currency&search.date.gte=2024-01-01T00:00:00Z&search.date.lte=2024-12-31T23:59:59Z"Filtered Chart with Search Parameters
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&search.type=MID&search.source=SNB&limit=50"Comprehensive Currency Pair Analysis
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&search.base_currency=USD&search.target_currency=EUR&search.date.gte=2025-07-01&search.date.lte=2025-07-31&search.type=SELL&search.source=SNB&color=hsl(58, 70%, 50%)"This example demonstrates:
- Specific currency pair: USD to EUR exchange rates
- Date range filtering: July 2025 data
- Transaction type: SELL transactions only
- Data source: SNB (Swiss National Bank)
- Custom styling: Specific HSL color for the chart
Gap Filling Example
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&search.date.gte=2025-07-01&search.date.lte=2025-07-31&fill_gaps=daily"This example demonstrates:
- Date range filtering: July 2025 data (31 days)
- Daily gap filling: Missing dates will be filled with null values
- Complete timeline: Returns 31 data points, one for each day in the range
Monthly Gap Filling Example
curl -X GET "{{base_url}}/v1/charts/line?rec_type=currency_pairs&x_field=date&y_field=rate&search.date.gte=2025-01-01&search.date.lte=2025-12-31&fill_gaps=monthly"This example demonstrates:
- Date range filtering: Full year 2025 data
- Monthly gap filling: Missing months will be filled with null values
- Complete timeline: Returns 12 data points, one for each month
Response:
[
{
"id": "series",
"color": "hsl(120, 70%, 50%)",
"data": [
{
"x": "2024-01-01",
"y": 1.0923
},
{
"x": "2024-01-02",
"y": 0
},
{
"x": "2024-01-03",
"y": 1.0931
},
{
"x": "2024-01-04",
"y": 0
},
{
"x": "2024-01-05",
"y": 1.0940
}
]
}
]Response Format
The API returns an array of chart series in Nivo-compatible format. When no group_by is specified, a single series with id: "series" is returned.
Single Series Response (No Group By)
[
{
"id": "series",
"color": "hsl(58, 70%, 50%)",
"data": [
{
"x": "2025-07-30",
"y": 1.150009
},
{
"x": "2025-07-31",
"y": 1.138944
}
]
}
]Multi-Series Response (With Group By)
[
{
"id": "EUR",
"color": "hsl(58, 70%, 50%)",
"data": [
{
"x": "2024-01-01",
"y": 1.0923
},
{
"x": "2024-01-02",
"y": 1.0931
}
]
},
{
"id": "USD",
"color": "hsl(118, 70%, 50%)",
"data": [
{
"x": "2024-01-01",
"y": 0.9155
},
{
"x": "2024-01-02",
"y": 0.9148
}
]
}
]Response Fields
id: Series identifier (group value when usinggroup_by, otherwise "series")color: HSL color value for the seriesdata: Array of data pointsx: X-axis value (formatted as string, dates are simplified to YYYY-MM-DD format)y: Y-axis value (numeric, compatible with Nivo charts)
Error Handling
| Status Code | Description | Common Causes |
|---|---|---|
| 400 | Bad Request | Missing required parameters, invalid date format, unsupported record type |
| 403 | Forbidden | Insufficient permissions for the record type |
| 404 | Not Found | No data available for the specified criteria |
| 500 | Internal Server Error | Database connection issues, query execution errors |
Best Practices
- Use appropriate date ranges: Limit date ranges to avoid performance issues
- Set reasonable limits: Use
limitparameter to control data volume (max 1000) - Group by meaningful fields: Use
group_byto create meaningful chart series - Cache results: Consider caching chart data for frequently accessed queries
- Monitor performance: Large datasets may require pagination or filtering
- Use specific filters: Combine multiple search parameters for precise data selection
- Validate date formats: Use RFC3339 format for date filters
- Consider data sources: Different sources may have varying data quality and availability