A multi-line chart built with Bootstrap 6 and inline SVG that compares website sessions from organic search, paid ads and email. Tabs switch between 7 days, 30 days and 12 months, the legend buttons show or hide each line, and a crosshair tooltip lists all values for one day. Use this line chart template as a traffic chart, an analytics line graph or a time series chart in dashboards and marketing reports.
How it works
The root .mlc-root holds a header with Bootstrap 6 nav nav-tabs, a .mlc-legend and the .mlc-plot with an empty svg.mlc-svg.
script.js starts with SERIES (key, label, colour) and DATA, which has one array per channel for 7d, 30d and 12m. The last value of each array is today or the current month; datesFor() counts backwards from today (no years shown).
draw() measures the plot width, picks a round tick step, and draws gridlines, axis labels, the "Sessions per day" unit and one path.mlc-line per visible channel. It redraws on resize.
Moving the pointer or touching the chart calls setActive(): a dashed crosshair and a dot per line move to the nearest point, and .mlc-tip lists the date and all visible values.
The legend buttons show each channel's total. Clicking one toggles aria-pressed and hides or shows its line; the last visible channel cannot be hidden.
Customization
DATAinscript.js: paste your own arrays (any length) or fill it withfetch()beforesetRange()runs.SERIESinscript.js: rename channels, change the line colours or add a fourth channel with a matching array.UNIT_LABELandHEIGHTinscript.js: the unit text above the y axis and the chart height on wide screens.Minscript.js: chart margins, for example more left space for long y labels.--mlc-accent,--mlc-gridand--mlc-bginstyle.css: active tab and focus colour, gridline colour and page background.stroke-widthin.mlc-line: thinner or bolder lines.
Use cases
- Marketing dashboards: compare traffic from organic, paid and email campaigns
- SaaS admin panels: sign-ups or active users per plan over time
- Sales reports: revenue by region across days or months
Accessibility
The tabs follow the WAI-ARIA tabs pattern: role="tablist", aria-selected, roving tabindex, and Left/Right/Home/End move and select. The plot is focusable: Left and Right step through the points, Home and End jump to the ends, Escape hides the crosshair, and each step is announced through a polite live region. A visually hidden table lists every date with all three values and is rebuilt for each range. Legend toggles are buttons with aria-pressed, and channel names are always written next to their colour.
Bootstrap 6 notes
Built on Bootstrap 6.0.0-alpha.1 (alpha APIs can still change). The tabs reuse the nav nav-tabs look but are driven by script.js, because all ranges share one chart panel instead of separate .tab-panes. The root has data-bs-theme="light" so it stays light in dark mode.