Function: chartToJSON()
ts
function chartToJSON(chart, options?): EncodedFigure;The chart's current input figure (data, layout, config, frames, datasets) encoded as JSON-safe data: JSON.stringify the result to save it, and pass it (or the string) to figureFromJSON or fromJSON to restore it. Keys the chart does not have are left out. The chart is not modified.
Style functions (ADR-012) warn once per path: on arrayOk attributes of registered traces they are evaluated into per-point arrays, elsewhere (e.g. config.renderHover) they are dropped.
Parameters
| Parameter | Type |
|---|---|
chart | ChartFigureSource |
options | ChartToJSONOptions |
Returns
Example
ts
localStorage.setItem('fig', JSON.stringify(chartToJSON(chart)));
const restored = fromJSON(el, localStorage.getItem('fig')!);