{"record":{"id":"b51a1b17aa244144","repo":"plotly/plotly.js","slug":"array-attribute-refattr-has-more-entries-than-ex","errorCode":null,"errorMessage":"Array attribute <refAttr> has more entries than expected, truncating to <expectedLen>","messagePattern":"Array attribute <refAttr> has more entries than expected, truncating to <expectedLen>","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/plots/cartesian/axes.js","lineNumber":174,"sourceCode":" *     extraOption if there is no axis)\n * extraOption: aside from existing axes with this letter, what non-axis value is allowed?\n *     Only required if it's different from `dflt`\n */\naxes.coerceRefArray = function(containerIn, containerOut, gd, attr, dflt, extraOption, expectedLen) {\n    const axLetter = attr.charAt(attr.length - 1);\n    var axlist = gd._fullLayout._subplots[axLetter + 'axis'];\n    const refAttr = attr + 'ref';\n    var axRef = containerIn[refAttr];\n\n    // Build the axis list, which we use to validate the axis references\n    if(!dflt) dflt = axlist[0] || (typeof extraOption === 'string' ? extraOption : extraOption[0]);\n    axlist = axlist.concat(axlist.map(x => x + ' domain'));\n    axlist = axlist.concat(extraOption ? extraOption : []);\n\n    // Handle array length mismatch\n    if(axRef.length > expectedLen) {\n        // if the array is longer than the expected length, truncate it\n        Lib.warn('Array attribute ' + refAttr + ' has more entries than expected, truncating to ' + expectedLen);\n        axRef = axRef.slice(0, expectedLen);\n    } else if(axRef.length < expectedLen) {\n        // if the array is shorter than the expected length, extend using the default value\n        Lib.warn('Array attribute ' + refAttr + ' has fewer entries than expected, extending with default value');\n        axRef = axRef.concat(Array(expectedLen - axRef.length).fill(dflt));\n    }\n\n    // Clean all axis references, replace with default if invalid\n    for(var i = 0; i < axRef.length; i++) {\n        axRef[i] = axisIds.cleanId(axRef[i], axLetter, true) || axRef[i];\n        if(!axlist.includes(axRef[i])) axRef[i] = dflt;\n    }\n\n    containerOut[refAttr] = axRef;\n    return axRef;\n};\n\n/*","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plots/cartesian/axes.js#L156-L192","documentation":"When normalizing an axis array attribute referenced across subplot domains (e.g. axis anchors or similar ref arrays evaluated per domain), plotly.js expects axRef to have exactly one entry per expected slot (expectedLen, derived from the axis list and extra options). If the array is longer, it logs this warning and truncates it to expectedLen, silently dropping extra entries.","triggerScenarios":"Passing an array-valued axis reference attribute with more elements than there are target axes/domains, e.g. supplying more entries than the number of axes in the subplot grid that the attribute applies to.","commonSituations":"Copy-pasting a multi-axis config and not trimming the array after removing subplots; generating arrays programmatically with one entry per data series instead of per axis; upgrading to a version that changed the expected length computation.","solutions":["Trim the array to match the number of expected axes/domains before setting the layout.","Count the actual axes in your grid and build the array from that count, not from data series count.","Check the number of warnings to identify which attribute (refAttr) carries the extra entries and remove the surplus values."],"exampleFix":"// before\nlayout.xaxis.arrayref = ['x', 'x2', 'x3']; // grid has only 2 axes\n// after\nlayout.xaxis.arrayref = ['x', 'x2'];","handlingStrategy":"validation","validationCode":"function fitAxisRefArray(arr, expectedLen, dflt) {\n  if (!Array.isArray(arr)) throw new TypeError('expected an array');\n  if (arr.length > expectedLen) throw new RangeError(`array has ${arr.length} entries, expected at most ${expectedLen}`);\n  return arr.slice();\n}","typeGuard":"const hasExactOrFewerEntries = (arr, n) => Array.isArray(arr) && arr.length <= n;","tryCatchPattern":null,"preventionTips":["Size axis reference arrays from the subplot grid axis count, not data series count.","Recompute arrays whenever you add/remove subplots.","Read the warning's refAttr name to find the offending attribute.","Write one entry per axis including domain pseudo-entries."],"tags":["layout","axes","array-length"],"backgroundTag":"array-length-mismatch","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}