You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-apexcharts方形图案系列显示异常,需实现预期样式

解决react-apexcharts方形图案填充不符合预期的问题

问题说明

我正在使用react-apexcharts,希望在图表上绘制圆形、星形、方形系列。尝试通过以下pattern配置实现方形图案,但显示效果不符合预期:

fill: {
  type: 'pattern',
  pattern: {
    style: "squares",
    width: 6,
    height: 6,
    strokeWidth: 1,
  },
}

当前效果:
我的尝试效果

期望实现的方形系列样式:
预期样式

解决方案

react-apexcharts默认的squares样式是空心方格,要实现实心方块效果,可通过以下两种方式调整:

方式1:自定义SVG图案填充

使用custom类型的pattern,传入实心方块的SVG代码,精准控制样式:

fill: {
  type: 'pattern',
  pattern: {
    type: 'custom',
    svg: '<svg width="6" height="6" viewBox="0 0 6 6"><rect width="6" height="6" fill="#你的目标颜色"/></svg>'
  }
}

可调整SVG的宽高、填充色,匹配你需要的方块大小和密度。

方式2:修改默认pattern参数

保留squares样式,通过设置填充色、隐藏边框来实现实心效果:

fill: {
  type: 'pattern',
  pattern: {
    style: "squares",
    width: 6,
    height: 6,
    strokeWidth: 0, // 移除边框
    fill: "#你的目标颜色", // 设置方块填充色
    strokeColor: "#你的目标颜色" // 若保留边框,需让边框色与填充色一致
  }
}

补充:圆形、星形图案实现

  • 圆形:用style: "circles"配合参数调整实现实心圆:
fill: {
  type: 'pattern',
  pattern: {
    style: "circles",
    width: 8,
    height: 8,
    strokeWidth: 0,
    fill: "#你的目标颜色"
  }
}
  • 星形:apexcharts无内置星形样式,需自定义SVG实现:
fill: {
  type: 'pattern',
  pattern: {
    type: 'custom',
    svg: '<svg width="10" height="10" viewBox="0 0 10 10"><polygon points="5,0 6.1,3.5 9.5,3.5 6.8,5.7 7.9,9.1 5,7 2.1,9.1 3.2,5.7 0.5,3.5 3.9,3.5" fill="#你的目标颜色"/></svg>'
  }
}

内容的提问来源于stack exchange,提问作者supriya singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 23:22:52