From 427c593e42ad0c5d23e9200ce17fd61fbdddfae0 Mon Sep 17 00:00:00 2001 From: cat0825 <1759138827@qq.com> Date: Sun, 31 May 2026 13:36:23 +0800 Subject: [PATCH] docs: clarify explicit grid tick values --- docs/marks/grid.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/marks/grid.md b/docs/marks/grid.md index d9d20180da..7c04e8c597 100644 --- a/docs/marks/grid.md +++ b/docs/marks/grid.md @@ -61,7 +61,24 @@ See the [axis mark](./axis.md) for more details and examples. ## Grid options -The optional *data* is an array of tick values — it defaults to the scale’s ticks. The grid mark draws a line for each tick value, across the whole frame. +The optional *data* is an array of tick values; if omitted, the mark computes its own ticks from the corresponding scale. To use the scale’s **ticks** option, use an implicit grid by setting the scale’s **grid** option, or pass the tick values directly to an explicit grid mark. + +For example, to align a grid with explicit tick values, pass the values to both the axis and grid marks: + +:::plot +```js +Plot.plot({ + x: { + domain: [new Date(2026, 2, 9), new Date(2026, 2, 11)] + }, + marks: [ + ((ticks) => [Plot.gridX(ticks), Plot.axisX(ticks)])( + ["2026-03-09", "2026-03-10", "2026-03-11"].map((d) => new Date(d)) + ) + ] +}) +``` +::: The following options are supported: