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

如何让ChartJS框注释仅显示左右边框而非上下边框?

解决ChartJS Box Annotation仅显示左右边框的问题

要实现Box Annotation只显示左右边框、隐藏上下边框,你可以通过单独控制各边的边框宽度或颜色来实现,具体有两种常用配置方式:

方式一:单独设置各边的边框宽度

在box annotation的配置项中,将borderTopWidth和borderBottomWidth设为0,同时保留borderLeftWidth和borderRightWidth为你需要的宽度:

annotations: {
  box1: {
    type: 'box',
    xMin: 2,
    xMax: 4,
    yMin: 0,
    yMax: 100,
    // 核心配置
    borderLeftWidth: 2,
    borderRightWidth: 2,
    borderTopWidth: 0,
    borderBottomWidth: 0,
    borderColor: '#ff0000', // 统一设置边框颜色
    backgroundColor: 'rgba(255, 0, 0, 0.1)' // 可选:设置背景透明度
  }
}

方式二:通过边框宽度数组控制

也可以使用borderWidth数组分别指定四个边的宽度,顺序为上、右、下、左,把上下对应的位置设为0即可:

annotations: {
  box1: {
    type: 'box',
    xMin: 2,
    xMax: 4,
    yMin: 0,
    yMax: 100,
    // 核心配置:[上, 右, 下, 左]
    borderWidth: [0, 2, 0, 2],
    borderColor: '#ff0000',
    backgroundColor: 'rgba(255, 0, 0, 0.1)'
  }
}

如果需要给左右边框设置不同颜色,也可以用borderColor数组(顺序同上),或者单独设置borderLeftColor和borderRightColor。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 20:37:32