Skip to main content

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_chart and save_to_local_storage control restore behavior

Where It Fits

  • externalSaveLoadAdapter is passed in through chart configuration
  • LocalStorageExternalSaveLoadAdapter can wrap another adapter to add a local fallback cache
  • ExternalDrawingsPersistenceBridge keeps drawings in sync with symbol changes and drawing events

Function Reference

Layout Functions

These functions are used to save and restore chart layouts.

FunctionPurpose
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.

FunctionPurpose
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.

FunctionPurpose
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.

FunctionPurpose
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

  1. The chart receives externalSaveLoadAdapter in its options.
  2. The adapter is used for layout and template persistence.
  3. The drawings bridge listens for drawing events and symbol changes.
  4. If local cache support is enabled, the chart can restore recent state faster on startup.