Repository navigation
Description
Description
A monthly bar chart fails to render when its date strings are displayed on a category axis and the trace retains xperiod: 'M1'. This can occur when reusing a date-chart configuration for a categorical view.
With xaxis.type: 'category', Plotly.newPlot throws TypeError: Cannot read properties of undefined (reading '0'). Removing xperiod makes the category chart render. Keeping the period and using xaxis.type: 'date' also works. The failure occurs on the first newPlot call; no updates or interactions are needed.
The xperiod documentation says it is only relevant on date axes. I would expect it to be ignored on a category or linear axis, allowing the chart to render. Plotly.validate(data, layout) returns undefined for the failing example.
The same failure occurs with yperiod on a non-date y axis. For bar and waterfall, the affected y-period path is used by horizontal traces (orientation: 'h'). Scatter is also affected.
Screenshots/Video
The comparison uses the same three dates and values in separate Plotly.newPlot calls:
| Configuration | Observed result |
|---|---|
Category axis, no xperiod |
Three bars render |
Category axis, xperiod: 'M1' |
TypeError; no bars render |
Date axis, xperiod: 'M1' |
Three bars render |
Steps to reproduce
CodePen-ready (HTML: <script src="https://cdn.plot.ly/plotly-4.3.0.js"></script><div id="gd"></div>). Run each JavaScript example separately and check the console.
Category-axis example:
const data = [{
type: 'bar',
x: ['2026-01-15', '2026-02-15', '2026-03-15'],
y: [4, 1, 3],
xperiod: 'M1'
}];
const layout = {xaxis: {type: 'category'}};
async function run() {
console.log('Plotly:', Plotly.version);
console.log('Plotly.validate:', Plotly.validate(data, layout));
try {
await Plotly.newPlot('gd', data, layout);
console.log('Rendered successfully');
} catch (error) {
console.error(error);
}
}
run();Remove xperiod: 'M1' and rerun: the three bars render. Alternatively, keep the period and change the axis type to 'date': the three bars also render.
Output for the category-axis example:
Plotly: 4.3.0
Plotly.validate: undefined
TypeError: Cannot read properties of undefined (reading '0')
A numeric axis also triggers the failure:
const data = [{
type: 'bar',
x: [1, 2, 3],
y: [4, 1, 3],
xperiod: 2
}];
const layout = {xaxis: {type: 'linear'}};
async function run() {
console.log('Plotly:', Plotly.version);
console.log('Plotly.validate:', Plotly.validate(data, layout));
try {
await Plotly.newPlot('gd', data, layout);
console.log('Rendered successfully');
} catch (error) {
console.error(error);
}
}
run();This throws with 'bar', 'scatter', and 'waterfall'. Removing xperiod allows each of these three trace types to render. Validation returns undefined in all six cases.
For yperiod, a horizontal bar provides a corresponding minimal example:
const data = [{
type: 'bar',
orientation: 'h',
x: [4, 1, 3],
y: [1, 2, 3],
yperiod: 2
}];
const layout = {yaxis: {type: 'linear'}};
async function run() {
console.log('Plotly:', Plotly.version);
console.log('Plotly.validate:', Plotly.validate(data, layout));
try {
await Plotly.newPlot('gd', data, layout);
console.log('Rendered successfully');
} catch (error) {
console.error(error);
}
}
run();This produces the same TypeError and undefined validation result. Changing type to 'waterfall' also throws. For scatter, change type to 'scatter' and remove orientation. Removing yperiod lets each example render.
The category-axis case also has a y-axis counterpart: a horizontal bar with the three date strings in y, yperiod: 'M1', and yaxis.type: 'category' throws. Removing yperiod, or using yaxis.type: 'date' with the same monthly period, renders successfully.
Notes
Reproduced with the unminified Plotly.js 4.3.0 npm bundle and a local development build of main cf771fa, in Google Chrome 157.0.8103.80 on Windows 11. Both builds show the same crashes and successful controls.
The calculation code appears to assume that period boundaries exist whenever the period alignment flag is set. For a non-date axis, alignPeriod returns only {vals: vals}, but bar calculation then accesses pObj.ends[i]. Scatter and waterfall have a similar pattern.
The horizontal bar and waterfall y-period paths read the same missing pObj.ends field. Scatter's y-period branch accesses yObj.ends[i] after the same early return.
Activity