Plot passes null to arrayLike
#2456
|
I’m not sure if this is a bug or if I missed something, so I’m writing this as a question: Why does the following chart config throw an error? Plot.plot({
x: { type: 'time', },
marks: [
Plot.tickX(
[new Date('2026-01-01'), new Date('2026-01-03')],
{ transform: (data) => data }
)
]
})
|
Replies: 1 comment 1 reply
|
The In Plot’s You do not need a transform for this example. const data = [
new Date("2026-01-01"),
new Date("2026-01-03")
];
Plot.plot({
x: {type: "time"},
marks: [Plot.tickX(data)]
});If you intentionally want a mark transform that leaves the data unchanged, preserve both values: Plot.tickX(data, {
transform: (data, facets) => ({data, facets})
});If what you meant was an x-channel accessor, put the function on Plot.tickX(data, {x: d => d});For filtering or reshaping rows, use a built-in transform such as |
The
Datevalues andx: {type: "time"}are fine. The problem is the mark-leveltransformcontract.In Plot’s
Mark.initialize, a mark transform is destructured as{data, facets}. Your(data) => datareturns the bare array, so Plot ends up withdata === undefined; the laterarrayLike/inerror is just the downstream symptom. The docs state the same contract: a custom transform receives(data, facets, options)and must return a{data, facets}object (https://observablehq.com/plot/features/transforms#transformoptions-transform).You do not need a transform for this example.
tickXdefaults itsxchannel to the identity accessor, so this is enough: