{"spec_id":"line-filled","library":"muix","language":"javascript","code":"// anyplot.ai\n// line-filled: Filled Line Plot\n// Library: muix 9.17.0 | JavaScript 22.23.4\n// Quality: 86/100 | Updated: 2026-11-08\nimport { LineChart } from \"@mui/x-charts/LineChart\";\nimport { ChartsReferenceLine } from \"@mui/x-charts/ChartsReferenceLine\";\nimport { ChartsGrid } from \"@mui/x-charts/ChartsGrid\";\n\nconst t = window.ANYPLOT_TOKENS;\n\n// Constants\nconst BASELINE = 0; // the fill runs down to zero, so the filled height stays proportional to the value\nconst FILL_TOP_OPACITY = 0.5; // semi-transparent fill, alpha 0.3–0.5, lighter towards the baseline\nconst FILL_BOTTOM_OPACITY = 0.3;\n\n// Columns: set these to your data's column names\nconst DATE = \"Date\"; // role: x\nconst VISITORS = \"Unique visitors\"; // role: y\n\n// Data: replace this block with your own records, one object per row\n// Daily unique visitors over 60 days of a content-marketing push, with weekend dips.\nconst data = (() => {\n  let seed = 11;\n  const rand = () => {\n    seed = (seed * 1103515245 + 12345) & 0x7fffffff;\n    return seed / 0x7fffffff;\n  };\n  const start = new Date(2026, 0, 5);\n  return Array.from({ length: 60 }, (_, i) => {\n    const date = new Date(start);\n    date.setDate(start.getDate() + i);\n    const weekendDip = date.getDay() === 0 || date.getDay() === 6 ? 0.7 : 1;\n    const noise = 1 + (rand() - 0.5) * 0.16;\n    return { [DATE]: date, [VISITORS]: Math.round(3200 * (1 + i * 0.013) * weekendDip * noise) };\n  });\n})();\n\n// Plot: reads only data and the constants above\nconst rows = [...data].sort((a, b) => a[DATE] - b[DATE]);\nconst dates = rows.map((d) => d[DATE]);\nconst values = rows.map((d) => d[VISITORS]);\nconst mean = Math.round(values.reduce((s, v) => s + v, 0) / values.length);\nconst formatValue = (v: number) => v.toLocaleString(\"en-US\");\nconst formatDate = (d: Date) => d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\", year: \"numeric\" });\n\nconst TITLE = \"Website Traffic Growth · line-filled · javascript · muix · anyplot.ai\";\nconst SUBTITLE = `${values.length} observations · ${formatDate(dates[0])} – ${formatDate(dates[dates.length - 1])} · range ${formatValue(Math.min(...values))} to ${formatValue(Math.max(...values))}`;\nconst HEADER_H = 80;\nconst FILL_ID = \"lineFilledGradient\";\n\nexport default function Chart() {\n  const { width, height } = window.ANYPLOT_SIZE;\n\n  return (\n    <div style={{ width, height, display: \"flex\", flexDirection: \"column\" }}>\n      <div style={{ height: HEADER_H, padding: \"16px 40px 0 108px\", boxSizing: \"border-box\" }}>\n        <div style={{ fontSize: 22, fontWeight: 600, color: t.ink, lineHeight: 1.25 }}>{TITLE}</div>\n        <div style={{ fontSize: 15, color: t.inkSoft, marginTop: 6 }}>{SUBTITLE}</div>\n      </div>\n      <LineChart\n        width={width}\n        height={height - HEADER_H}\n        skipAnimation\n        hideLegend\n        margin={{ top: 16, right: 48, bottom: 16, left: 24 }}\n        xAxis={[\n          {\n            data: dates,\n            scaleType: \"time\",\n            label: DATE,\n            height: 64,\n            tickNumber: 9,\n            valueFormatter: (d: Date) => d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\" }),\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        yAxis={[\n          {\n            min: BASELINE,\n            label: VISITORS,\n            width: 88,\n            valueFormatter: formatValue,\n            tickLabelStyle: { fontSize: 14, fill: t.inkSoft },\n            labelStyle: { fontSize: 16, fill: t.ink },\n          },\n        ]}\n        series={[\n          {\n            id: \"values\",\n            data: values,\n            label: VISITORS,\n            color: t.palette[0],\n            area: true,\n            baseline: BASELINE,\n            showMark: false,\n            curve: \"monotoneX\",\n            valueFormatter: (v: number | null) => (v == null ? \"\" : formatValue(v)),\n          },\n        ]}\n        sx={{\n          \"& .MuiLineChart-area\": { fill: `url(#${FILL_ID})` },\n          \"& .MuiLineChart-line\": { strokeWidth: 3 },\n          \"& .MuiChartsAxis-line\": { stroke: t.inkSoft },\n          \"& .MuiChartsAxis-tick\": { stroke: t.inkSoft },\n          \"& .MuiChartsGrid-line\": { stroke: t.grid, strokeWidth: 1 },\n        }}\n      >\n        <defs>\n          <linearGradient id={FILL_ID} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <stop offset=\"0%\" stopColor={t.palette[0]} stopOpacity={FILL_TOP_OPACITY} />\n            <stop offset=\"100%\" stopColor={t.palette[0]} stopOpacity={FILL_BOTTOM_OPACITY} />\n          </linearGradient>\n        </defs>\n        {/* Gridlines drawn after the fill so they stay visible through it */}\n        <ChartsGrid horizontal />\n        <ChartsReferenceLine\n          y={mean}\n          label={`Mean ${formatValue(mean)}`}\n          labelAlign=\"start\"\n          spacing={{ x: 12, y: 8 }}\n          lineStyle={{ stroke: t.inkSoft, strokeDasharray: \"6 4\", strokeWidth: 1.5 }}\n          labelStyle={{ fontSize: 14, fill: t.inkSoft }}\n        />\n      </LineChart>\n    </div>\n  );\n}\n"}