Skip to content

[Bug] echarts 在node:16.17.0 docker 镜像下通过node canvas生成图片背景颜色出错 #17623

@Cyberhan123

Description

@Cyberhan123

Version

5.3.3

Link to Minimal Reproduction

No response

Steps to Reproduce

镜像需要安装字体

RUN apt-get -y update \
&& apt-get -y install ttf-wqy-zenhei fonts-wqy-microhei

下面是复现demo

var echarts = require('echarts');
const { createCanvas } = require('canvas');

const canvas = createCanvas(800, 600);
// ECharts 可以直接使用 node-canvas 创建的 Canvas 实例作为容器
const chart = echarts.init(canvas);

// 像正常使用一样 setOption
chart.setOption({
  title: {
    show: true,
    text: '复现测试,这里会变成黑色的背景',
    left: 'center',
    top: 'center',
    fontSize: 30,
  },
  tooltip: {
    trigger: 'item',
  },
  legend: {
    width: 30,
    icon: 'circle',
  },
  series: [
    {
      // name: 'Access From',
      type: 'pie',
      radius: ['40%', '70%'],
      label: {
        show: false,
      },
      labelLine: {
        show: false,
      },
      data: [],
    },
  ],
});

// 通过 Response 输出 PNG 图片
res.writeHead(200, {
  'Content-Type': 'image/png'
});
res.write(renderChart().toBuffer('image/png'));
res.end();

### Current Behavior

echatrs 默认背景为透明,但是实际生成的背景却变成黑色

### Expected Behavior

期待生成的背景为透明的背景

### Environment

```markdown
- OS: node:16.17.0
- Browser: node- canvas
- Framework:

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpendingWe are not sure about whether this is a bug/new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions