linear axis: "reverse" breaks tick align 'inner'

未关闭 适合新手
#12,378 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Fardin7798 已经在做这个了。

开始于 2026年11月6日。

  • #12379 来自 @Fardin7798 —— 未关闭
  • #12385 来自 @chiragbitoni —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
77/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
chart.js, javascript

调研方向

从 scale.js 中的 computeLabelItem 开始,检查 inner 刻度对齐如何计算第一个和最后一个刻度的标签位置。使用提供的配置,将现有行为与反向线性轴进行比较。更新对齐方式,使这些刻度保持在轴内,然后运行相关的 scale 和刻度对齐测试;反向轴能够将两端的刻度都朝内渲染时,即为完成。

由索引模型根据 Issue 内容生成。

描述

type: bug
Expected behavior

When the axis is drawn and "align": "inner" is set for ticks, the first and last tick shall be painted inwards the axis line.

Current behavior

When the axis is drawn in standard direction, "align": "inner" works for ticks

Image

But when "reverse": "true", the first and last tick are explicitly rendred out of the axis!

Image
Reproducible sample

don't have one. Use the codepen and replace the cfg with the one below

Optional extra steps/info to reproduce

Cfg for the codepen. Clearly shows the problem

var myChart = new Chart(ctx, {
  type: "line",
  data: {
    //labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
      {
        label: "# of Votes",
        indexAxis: "x",
        data: [
          { x: 200, y: 12 },
          { x: 451, y: 14 },
          { x: 999, y: 14 }
        ]
      }
    ]
  },
  options: {
    scales: {
      x: {
        axis: "x",
        type: "linear",
        min: 200,
        max: 1000,
        reverse: true,
        ticks: {
          align: "inner"
        }
      },
      y: {
        axis: "y",
        min: 0,
        max: 20
      }
    }
  }
});
Possible solution

scale.js computeLabelItem

Consider reversed axis setting here

case 'inner':
          if (i === ilen - 1) {
            left -= width;
          } else if (i > 0) {
            left -= width / 2;
          }
break;

Context

No response

chart.js version

v4.5.1

Browser name and version

Chrome 152

Link to your project

No response

主要语言
JavaScript
星标
67.8k
派生
12k
平均合并
6 小时 15 分钟
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

chartjs/Chart.js 的其他 Issue

查看 chartjs/Chart.js 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。