Skip to content

Function: toImage() ​

ts
function toImage(target, options?, chartOptions?): Promise<string>;

Plotly's toImage: render the chart in el — or a figure object ({ data, layout, config }), drawn offscreen without a chart on the page — to an image. Resolves to a data URL. See Chart.toImage for the options (format, width, height, scale, transparent).

Parameters ​

ParameterType
target| HTMLElement | FigureInput<object, LayoutInput>
optionsToImageOptions
chartOptions?ChartOptions

Returns ​

Promise<string>

Example ​

ts
const url = await toImage(el, { format: 'jpeg', width: 800, height: 400 });
const url2 = await toImage({ data, layout }, { scale: 2 }); // no chart needed

Released under the MIT License.