plotly/plotly.js · warning

c2dApply: axArray and valArray must be the same length

Error message

c2dApply: axArray and valArray must be the same length

What it means

c2dApply converts calcdata values to data values using each axis's c2d mapping; it requires one axis (or null) per value. When array lengths differ, it warns 'c2dApply: axArray and valArray must be the same length' and proceeds, using undefined for missing axes and returning raw values where no axis exists.

Source

Thrown at src/components/fx/helpers.js:70

 * for converting x/y values from calc space to data space. axArray and valArray are arrays
 * rather than single values because in the case of stacked subplots, there may be multiple axes
 * (and therefore multiple data values) corresponding to a single hover or click event.
 *
 * For linear and log axes, this conversion has no effect beyond validating the inputs.
 * However, for some axes types, the converted values may be of a different type than the
 * inputs:
 *  - For category axes, `c2d` converts calcdata values (numeric) into category labels (strings)
 *  - For date axes, `c2d` converts calcdata values (numeric values in ms) into date strings
 *
 * For axes which don't define `c2d` (e.g. geo, map), the inputs are passed through untouched.
 *
 * @param {Array} axArray : axes corresponding to each value in valArray
 * @param {Array} valArray : calcdata values
 * @return {Array} : data values, computed by calling `ax.c2d` (if defined) on each input value
 */
exports.c2dApply = function (axArray, valArray) {
    if(axArray.length !== valArray.length) {
        Lib.warn('c2dApply: axArray and valArray must be the same length');
    }
    var out = new Array(valArray.length);
    for (var i = 0; i < valArray.length; i++) {
        var ax = axArray && axArray[i];
        out[i] = ax && ax.c2d ? ax.c2d(valArray[i]) : valArray[i];
    }
    return out;
};

exports.getDistanceFunction = function (mode, dx, dy, dxy) {
    if (mode === 'closest') return dxy || exports.quadrature(dx, dy);
    return mode.charAt(0) === 'x' ? dx : dy;
};

exports.getClosest = function (cd, distfn, pointData) {
    // do we already have a point number? (array mode only)
    if (pointData.index !== false) {
        if (pointData.index >= 0 && pointData.index < cd.length) {

View on GitHub (pinned to 1d090e0b5f)

Solutions

  1. Ensure axArray[i] corresponds to valArray[i]; rebuild axArray from the same loop that built valArray.
  2. If an axis is legitimately unknown for a value, push null/undefined explicitly so lengths match by design.
  3. Locate the caller (hover helpers) and check how axes arrays are constructed for multi-axis layouts.
  4. Update plotly.js if triggered by stock hover code on a supported multi-axis layout — it may be a fixed regression.
  5. As a workaround, avoid mixing axes arrays; process values per-axis in separate calls.

Example fix

// before
Fx.c2dApply(xAxesOnly, xvals); // xAxesOnly.length < xvals.length after filtering
// after
const axArray = xvals.map((_, i) => xAxes[i] || null);
Fx.c2dApply(axArray, xvals); // same length, nulls where no axis
Defensive patterns

Strategy: validation

Validate before calling

function safeC2dApply(axArray, valArray) {
  const ax = valArray.map((_, i) => (axArray && axArray[i]) || null);
  return exports.c2dApply(ax, valArray);
}

Type guard

function sameLength(a, b) {
  return Array.isArray(a) && Array.isArray(b) && a.length === b.length;
}

Try / catch

if (!sameLength(axArray, valArray)) {
  console.error('c2dApply length mismatch', axArray.length, valArray.length);
  return valArray; // pass through unconverted
}
return exports.c2dApply(axArray, valArray);

Prevention

When it happens

Trigger: Internal hover/zoom code calling exports.c2dApply with an axes array built from a different number of axes than the values array — e.g. multi-axis (xaxis/xaxis2) hover where one array was filtered or built per-subplot and the other wasn't.

Common situations: Custom code paths building axArray manually while reusing a valArray from another context; hover handlers over subplots where subplot arrays are spliced but value arrays are not; buggy plugins or forked plotly builds.

Related errors


AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02). Data as JSON: /api/errors/613d5bce2a252d81. Report an issue: GitHub.