[错误]:
作者: codeCraft-Ritik创建于 2026年9月10日更新于 2026年9月10日
标签bug
Expected vs Actual Behavior
- Expected: When
projectedValues = [-50, 0, 50]atindex = 0,labelLengthshould be0 - (-50) = 50. - Actual:
if (0)evaluates tofalse, causing the fallback calculation to assignlabelLength = 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