# @bitblit/ratchet-echarts

> Library for using echarts on Node

Latest version **5.1.122-alpha** (published 2025-11-03) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @bitblit/ratchet-echarts
pnpm add @bitblit/ratchet-echarts
yarn add @bitblit/ratchet-echarts
bun add @bitblit/ratchet-echarts
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 5.1.122-alpha |
| Published | 2025-11-03 |
| First published | 2022-08-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | bitblit |

## Links

- npm: https://www.npmjs.com/package/@bitblit/ratchet-echarts
- npm.io page: https://npm.io/package/@bitblit/ratchet-echarts

## Dependencies (3)

- [canvas](https://npm.io/package/canvas.md) 3.2.0
- [echarts](https://npm.io/package/echarts.md) 6.0.0
- [@bitblit/ratchet-common](https://npm.io/package/@bitblit/ratchet-common.md) 5.1.122-alpha

## Recent versions

- 5.1.122-alpha (latest) — 2025-11-03
- 6.1.231-alpha (alpha-2026-09-14-5) — 2026-09-14
- 6.1.230-alpha (alpha-2026-09-14-4) — 2026-09-14
- 6.1.229-alpha (alpha-2026-09-12-1) — 2026-09-13
- 6.1.228-alpha (alpha-2026-09-11-5) — 2026-09-11
- 6.1.227-alpha (alpha-2026-09-09-4) — 2026-09-10
- 6.1.226-alpha (alpha-2026-09-09-3) — 2026-09-10
- 6.1.225-alpha (alpha-2026-09-09-2) — 2026-09-10
- 6.1.223-alpha (alpha-2026-08-27-1) — 2026-08-27
- 6.1.222-alpha (alpha-2026-08-24-1) — 2026-08-24
- 6.1.221-alpha (alpha-2026-08-21-14) — 2026-08-22
- 6.1.220-alpha (alpha-2026-08-21-13) — 2026-08-22
- 6.1.217-alpha (alpha-2026-08-21-9) — 2026-08-22
- 6.1.216-alpha (alpha-2026-08-21-8) — 2026-08-22
- 6.1.215-alpha (alpha-2026-08-21-7) — 2026-08-22
- … 527 more at https://npm.io/package/@bitblit/ratchet-echarts/versions

## README

# node-echarts
Generate chart by [Apache ECharts](https://github.com/apache/incubator-echarts) in Nodejs.

This library is forked from [node-echarts](https://github.com/hellosean1025/node-echarts) to which it is highly
indebted.  I have forked it because that library appears to now be dormant, and I'd like to be able to use newer
versions of echarts, and the new prebuilt versions of canvas in my Lambda functions.  I also prefer typescript
and will be bringing in type information.

## Install

Note: Since this library depends on Echarts >= 5.x and node-canvas (canvas) >= 2.9.3, it auto-bundles in the 
correct native libraries (prebuilt) for Windows, OSX, and Linux - see [the canvas github page](https://github.com/Automattic/node-canvas) 
for details.  Therefore, all you have to do is:

```
npm install @bitblit/ratchet-echarts
```

### Special notes for AWS Lambda

Most important - you MUST set your lambda to have sufficient memory - probably 512Mb or more.  If you find yourself
getting timeouts with no errors logged after adding the library, you most likely have insufficient memory set.


If you are using AWS Lambda (either Node 14/16, or containers built from the AWS parent container for them), you will
likely encounter the error "/lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /var/task/node_modules/canvas/build/Release/libpng16.so.16)"

See [the node-canvas issue for more details](https://github.com/Automattic/node-canvas/issues/1779).  The solution
varies depending on how you use Lambda.  

### Using a custom docker container (1st way)
To make sure it is compatible with whatever the current build of the image is, we will build from scratch.  In our
docker container, we'll add :

```docker
# To build things in yarn
RUN yum -y install python3
RUN yum -y install pkgconfig make

# Specifically for building canvas
RUN yum -y install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel
```

And then, in the container we'll force a clean build, either by using
```docker
RUN npm install --build-from-source
```

or

```docker
RUN npm_config_build_from_source=true yarn install
```

### Using a custom docker container (alternate way)
Add this to your container:
```docker
# Bring these in to make echarts work...
# Also requires setting the LD_LIBRARY_PATH variable in the config
# https://github.com/Automattic/node-canvas/issues/1779
RUN yum -y install libuuid-devel libmount-devel
RUN cp /lib64/{libuuid,libmount,libblkid}.so.1 ${LAMBDA_TASK_ROOT}/node_modules/canvas/build/Release/
# End charts stuff
```

And then set an environment variable:
```
LD_LIBRARY_PATH="${LAMBDA_TASK_ROOT}/modules/api/node_modules/canvas/build/Release:${LD_LIBRARY_PATH}"
```

### Using one of the AWS Node options
Use a [prebuilt layer](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs)

## Usage

```typescript

import { EChartRatchet } from '../echart-ratchet';
import { EChartsOption } from 'echarts';
import fs from 'fs';

const options: EChartsOption = {
    // Some big echarts thing... see Echarts docs for how to build this
    //title: {
    //    text: 'test',
    //},
    //...
};

const canvasConfig: EChartCanvasConfig  = {
    width: 1000
    height: 500
}

const myChart: Buffer = await EChartRatchet.renderChart(options, canvasConfig);
fs.writeFileSync('somefile.png', myChart);

// Also could have just written
// await EChartRatchet.renderChartToPngFile('somefile.png', options, canvasConfig);

```

### EChartCanvasConfig

|name|type|default|description|
|---|---|---|---|
|width|Number|500|Image width|
|height|Number|500|Image height|

---
_Source: https://npm.io/package/@bitblit/ratchet-echarts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
