Overview
The external adapter is the persistence layer that connects the chart to your own storage, backend, or caching system.
What It Covers
The external adapter is used for:
- saving and loading layouts
- storing chart templates
- storing study templates
- saving and restoring drawings
How It Connects
The chart can receive an externalSaveLoadAdapter in its configuration options. From there, the library uses the adapter to store and restore:
- saved layouts
- chart templates
- study templates
- drawings
The library can also wrap your adapter with a local cache layer through LocalStorageExternalSaveLoadAdapter. That gives the chart a fallback copy of recent layouts, templates, and drawings when the external store is slow or unavailable.
How It Is Managed
- layout state is saved through the external adapter
- chart and study templates are saved through the same persistence path
- drawings are synchronized separately so they stay attached to the current symbol
- local cache metadata tracks the most recently active layout
- startup options such as
load_last_chartandsave_to_local_storagecontrol restore behavior
Where It Fits
externalSaveLoadAdapteris passed in through chart configurationLocalStorageExternalSaveLoadAdaptercan wrap another adapter to add a local fallback cacheExternalDrawingsPersistenceBridgekeeps drawings in sync with symbol changes and drawing events
Function Reference
Layout Functions
These functions are used to save and restore chart layouts.
| Function | Purpose |
|---|---|
saveLayout(layoutData) | Saves a layout and returns its ID. |
loadLayout(layoutId) | Loads a layout by ID. |
removeLayout(layoutId) | Deletes a saved layout. |
getLayouts() | Returns the available layout list. |
renameLayout(layoutId, newName) | Renames an existing layout. |
autosaveLayout(layoutId, layoutData) | Stores layout changes automatically. |
Chart Template Functions
These functions store reusable chart appearance setups.
| Function | Purpose |
|---|---|
saveChartTemplate(template) | Saves a chart template. |
getChartTemplates() | Returns saved chart templates. |
loadChartTemplate(templateId) | Loads a chart template by ID. |
removeChartTemplate(templateId) | Deletes a chart template. |
Study Template Functions
These functions store reusable indicator and study setups.
| Function | Purpose |
|---|---|
saveStudyTemplate(template) | Saves a study template. |
getStudyTemplates() | Returns saved study templates. |
removeStudyTemplate(templateId) | Deletes a study template. |
applyStudyTemplate(templateId) | Applies a study template to the chart. |
Drawing Functions
These functions keep annotations and drawing tools in sync with your storage layer.
| Function | Purpose |
|---|---|
saveDrawing(drawing) | Saves a drawing. |
loadDrawings(symbol) | Loads drawings for a symbol. |
getAllDrawings() | Returns every saved drawing. |
updateDrawing(drawing) | Updates an existing drawing. |
removeDrawing(drawingId) | Removes a saved drawing. |
Cache Layer
LocalStorageExternalSaveLoadAdapter can wrap a real adapter and keep a local copy of:
- layouts
- chart templates
- study templates
- drawings
This helps the chart restore the latest state even if the external store is unavailable.
How It Works With The Chart
- The chart receives
externalSaveLoadAdapterin its options. - The adapter is used for layout and template persistence.
- The drawings bridge listens for drawing events and symbol changes.
- If local cache support is enabled, the chart can restore recent state faster on startup.