Line Chart Drawing
A plain single-colour SVG curve: the stroke draws itself from left to right in two seconds when the block appears, then a light area settles underneath.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Data has 28 effects, including 1 free. Explore the category →
3 usage examples



How it works
The HTML holds nothing but an empty block, div.lcw-chart. The data sits on the root: data-values (comma-separated numbers), data-labels (one name per point) and data-title. From these the script builds an SVG drawing made of two paths: the line, in straight segments from one point to the next, and the surface it encloses down to the bottom of the block.
The drawing is computed at the block's real size, in pixels: the stroke is 3 px thick whatever the width, with no distortion. If the block changes size (phone rotated, column narrowing), the points are placed again at once.
The animation starts when 35% of the block is visible. The stroke is one dash as long as the whole curve, which the stylesheet slides over 2 s: it looks as if it were being drawn. Halfway through, the area starts to appear and stops at 30% opacity, fading towards the bottom.
The vertical scale fits the data, with a tenth of margin above and below. Set data-min and data-max to start from zero or to make two curves share one scale. The block shows no axis, no ticks, no dots: only the line and its area.
Accessibility
- Description read aloud: the block is an image (
role="img") whose name is built from your attributes: “Sign-ups per month. Jan 20, Feb 40, Mar 30…”. Numbers are written in the page language, withdata-unitwhen present. - Long series: that description lists every point. Beyond fifteen values or so, also offer a one-sentence summary or a table next to it.
- System setting that limits animations: the curve and its area are shown finished, with no progressive drawing.
- No hover, no focus: no tooltip, no clickable point. A precise value has to be written in the page.
- Thin stroke: 3 px wide. On a coloured background, check that
--lcw-colorstands out clearly.
Browser compatibility
Script-built SVG, stroke-dasharray and stroke-dashoffset animated in CSS, IntersectionObserver, ResizeObserver. In Chromium 149, Firefox 151 and WebKit 26.5, with the eight stock values over 560 px: a 592 dash, offset at 294 after 0.6 s and at 0 after 2.2 s, area at 0.30; at 390 px the path is recomputed (412 dash); two overlaid roots each get their own gradient identifier.
Without ResizeObserver (Chrome 51 to 63, Safari 12.1) the curve draws but no longer follows size changes. Without IntersectionObserver it draws on load. Without JavaScript the block stays empty.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0240-root" data-title="Sign-ups per month" data-labels="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug" data-values="20,40,30,70,55,90,75,110">
<div class="lcw-chart" role="img"></div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
data-values (HTML, on the root) |
20,40,30,70,55,90,75,110 | The series, at least two numbers. With only one, nothing is drawn. An entry that is not a number is skipped (the following labels shift by one). |
data-labels, data-title (HTML) |
eight months, “Sign-ups per month” | Point names and title, used only for the description read by screen readers. |
data-unit (HTML) |
absent | Unit for that description: % gives a percentage, any other text is appended to the number. |
data-min, data-max (HTML) |
absent | Bounds of the vertical scale. Without them the curve uses the full height. |
--lcw-color (CSS) |
#6366f1 | Stroke colour. |
--lcw-area (CSS) |
50% indigo | Tint of the area, dimmed further on display. transparent for a line alone. |
--lcw-height, --lcw-max-width (CSS) |
150px, 560px | Height of the drawing and the width it will not exceed. |
--lcw-bg, --lcw-min-height (CSS) |
#0a0a0f, 300px | Background and minimum height of the block around the drawing. |
FAQ
position: absolute, give them the same data-min and data-max, a transparent background and a colour each. If one has fewer points, reduce its width in proportion so the points stay aligned (the formula is in the second example). Each root creates its own gradient: they do not interfere.data-values redraws nothing at that moment. Values are read again when the block changes size or reappears. The simplest way: write the new values, hide the block (hidden), then show it again a moment later; the curve is then drawn afresh with the new figures.