A smooth SVG line chart with hover points, built with pure CSS and vanilla JavaScript and no chart library. This area chart example plots daily website visitors for the last 30 days with a gradient fill, axis labels and a crosshair tooltip for analytics dashboards, SaaS admin panels and traffic reports.
How it works
The root section.lc-card has a header with three figures (.lc-kpis), the focusable plot .lc-plot with an empty svg.lc-svg, an HTML tooltip .lc-tip and a visually hidden table.
The numbers come from DATA.values at the top of script.js, one value per day with the last value being today. Dates are computed from today and shown without a year, so the chart never looks out of date. draw() measures the plot, sets the SVG viewBox to its real pixel size and builds the gridlines, value labels (niceStep() picks round steps), weekly date labels, the .lc-area fill with a linearGradient and the .lc-path line. smoothPath() uses monotone cubic interpolation, so the curve is smooth but never overshoots the data.
select() moves the dashed .lc-cross line, the .lc-dot point and the tooltip to a day. Pointer movement over the plot picks the nearest day, and on touch screens a horizontal drag does the same while vertical scrolling still works (touch-action: pan-y). The tooltip shows the date, the value and the change against the previous day, flips to the left near the right edge and is placed above or below the line so it does not hide it. Today is selected on load. On window resize the chart is redrawn at the new width.
Customization
DATA.valuesinscript.js: your own daily numbers, oldest first; KPIs, labels and table update automatically.DATA.unit: the word after each value, e.g.ordersorsign-ups.DATA.ticks: approximate number of gridlines on the value axis.--lc-lineand--lc-fillon.lc-card: the line colour and the colour of the gradient area.--lc-height: chart height,16remon phones and20remfrom 760px.PADinscript.js: inner spacing for the axis labels.stroke-widthin.lc-path: a thinner or bolder line.
Use cases
- Website analytics: daily visitors, page views or sessions over the last month.
- SaaS dashboards: sign-ups or active users with the exact value per day.
- E-commerce reports: daily orders or revenue trends.
- Status and monitoring pages: requests or response times over time.
Accessibility
The plot is a role="slider" with aria-valuenow, aria-valuemax and an aria-valuetext such as "Tue, Nov 18: 1,502 visitors", so screen readers announce each day. Left and Right arrows move one day, Page Up and Page Down a week, Home and End jump to the first and last day, and the focus ring is clearly visible. The SVG and tooltip are aria-hidden; a visually hidden table.lc-sr lists all 30 dates and values.
Usage notes
Several charts can share a page; each one gets its own gradient id.