@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
| Option | Type | Default | Description |
|---|---|---|---|
| width | number | defaultWidth | Chart width in pixels |
| height | number | defaultHeight | Chart height in pixels |
| theme | string | defaultTheme | ECharts theme name for this render |
| outputPath | string | — | File path (only for renderToFile) |
| timeout | number | global timeout | Per-render timeout override in ms |
| deviceScaleFactor | number | 1 | Device pixel ratio for retina output (e.g., 2) |