@nestjsforge/echarts

Overview

NestJS module for server-side ECharts rendering with Puppeteer browser pool.

A production-ready NestJS module that renders Apache ECharts charts server-side using a Puppeteer browser pool. Inject EChartsService anywhere in your application and render charts to PNG buffers, Base64 strings, data URLs, or files without any browser on the client.

Key Features

  • Native NestJS DI — Inject EChartsService directly into any controller, service, or provider.
  • forRoot / forRootAsync — Synchronous and async configuration (useFactory, useClass, useExisting).
  • Browser pool — Manages a pool of headless Chromium instances for high-throughput rendering.
  • Concurrency control — Configure max concurrent renders to protect resources.
  • Graceful shutdown — Automatically closes all browser instances on application shutdown.
  • Themes — Register named ECharts themes (dark, custom JSON themes).
  • Serializable functions — Use JavaScript functions inside ECharts options (formatter, rich, etc.).
  • Typed exceptions — Structured error classes for renderer, pool, and shutdown failures.
  • Dual CJS/ESM — Ships both CommonJS and ES Module builds.
  • Fully tested — Unit and integration tests with Jest.

Quick Example

app.module.ts
import { EChartsModule } from '@nestjsforge/echarts';

@Module({
  imports: [
    EChartsModule.forRoot({
      poolSize: 2,
      timeout: 10_000,
      defaultTheme: 'dark',
    }),
  ],
})
export class AppModule {}
report.service.ts
import { EChartsService } from '@nestjsforge/echarts';

@Injectable()
export class ReportService {
  constructor(private readonly echarts: EChartsService) {}

  async getChartBuffer(): Promise<Buffer> {
    return this.echarts.renderToBuffer({
      xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed'] },
      yAxis: { type: 'value' },
      series: [{ data: [120, 200, 150], type: 'bar' }],
    });
  }
}