@nestjsforge/echarts

Render Methods

All available render methods: renderToBuffer, renderToBase64, renderToDataUrl, renderToFile, renderMany.

EChartsService exposes five render methods, all accepting an EChartsOption object and an optional RenderOptions override.

renderToBuffer

Renders the chart and returns a Node.js Buffer containing the PNG image data.

const buffer: Buffer = await this.echarts.renderToBuffer(option, {
  width: 1200,
  height: 630,
  theme: 'dark',
});

renderToBase64

Returns the PNG image as a Base64-encoded string (without the data URL prefix).

const base64: string = await this.echarts.renderToBase64(option);
// Returns: "iVBORw0KGgoAAAANSUhEUgAA..."

renderToDataUrl

Returns the PNG as a data URL, ready to embed in HTML img tags or CSS.

const dataUrl: string = await this.echarts.renderToDataUrl(option);
// Returns: "data:image/png;base64,iVBORw0KGgoAAAA..."

// Use in a response:
return { chartUrl: await this.echarts.renderToDataUrl(option) };

renderToFile

Renders the chart and writes it to a file. Returns the absolute path of the saved file.

const filePath: string = await this.echarts.renderToFile(option, {
  outputPath: '/tmp/charts/revenue-chart.png',
});

renderMany

Renders multiple charts concurrently (up to maxConcurrentRenders). Returns an array of Buffers in the same order as the input.

const options = [barChartOption, lineChartOption, pieChartOption];
const buffers: Buffer[] = await this.echarts.renderMany(options, {
  width: 800,
  height: 400,
});

RenderOptions

OptionTypeDefaultDescription
widthnumberdefaultWidthChart width in pixels
heightnumberdefaultHeightChart height in pixels
themestringdefaultThemeECharts theme name for this render
outputPathstringFile path (only for renderToFile)
timeoutnumberglobal timeoutPer-render timeout override in ms
deviceScaleFactornumber1Device pixel ratio for retina output (e.g., 2)