#1471·chartist

[错误]:

作者: codeCraft-Ritik创建于 2026年9月10日更新于 2026年9月10日
标签bug

Expected vs Actual Behavior

  • Expected: When projectedValues = [-50, 0, 50] at index = 0, labelLength should be 0 - (-50) = 50.
  • Actual: if (0) evaluates to false, causing the fallback calculation to assign labelLength = Math.max(axisLength - (-50), ...).

Suggested Fix

Check for index / undefined existence instead of numeric truthiness: TypeScript if (projectedValues[index + 1] !== undefined) { labelLength = projectedValues[index + 1] - projectedValue; } else { ... }

Reproduction

TypeScript import { LineChart, AutoScaleAxis } from 'chartist'; // Create a bipolar chart where the middle tick sits at projected coordinate 0 new LineChart('#chart', { labels: ['-50', '0', '50'], series: [[-50, 0, 50]] });

Chartist version

1.5.0 (latest / main)

内容来源: chartist-js/chartist