Core API
data-driven rendering
Charts turn data into visuals, but the data and labels must remain understandable.
const values = [30, 80, 55]; const max = Math.max(...values); bars.forEach((bar, index) => { bar.style.height = `${(values[index] / max) * 100}%`; });
Graphics, Media & UI
Charts turn data into visuals, but the data and labels must remain understandable.
Visual JavaScript should make state easier to understand. The code must stay connected to real data, user intent and accessibility.
A polished interface is not only animation. It is timing, feedback, labels, fallback states and predictable interaction.
data-driven rendering
Use motion or graphics to explain state, not to distract from it.
Keep text, labels and keyboard alternatives available.
Avoid layout-heavy loops and unnecessary repaints.
Examples
const values = [30, 80, 55]; const max = Math.max(...values); bars.forEach((bar, index) => { bar.style.height = `${(values[index] / max) * 100}%`; });
bar.style.height = "72px"; // The visual no longer comes from data.
Syntax reference
This is the practical reference part of the lesson. Each example has one job, a stable anchor and a small assignment, so the page works both as a course and as a developer reference when you need the syntax later.
A direct example of the topic.
const values = [30, 80, 55]; const max = Math.max(...values); bars.forEach((bar, index) => { bar.style.height = `${(values[index] / max) * 100}%`; });
A shortcut that makes the interface fragile.
bar.style.height = "72px"; // The visual no longer comes from data.
Users may ask the browser for less animation.
const prefersReducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches; if (!prefersReducedMotion) { element.animate(keyframes, options); }
Visuals should not be the only source of meaning.
<figure> <canvas aria-label="Monthly revenue chart"></canvas> <figcaption>Revenue increased over four months.</figcaption> </figure>
Code patterns
Use these examples when turning data, state and interaction into something visible.
A direct example of the topic.
const values = [30, 80, 55]; const max = Math.max(...values); bars.forEach((bar, index) => { bar.style.height = `${(values[index] / max) * 100}%`; });
A shortcut that makes the interface fragile.
bar.style.height = "72px"; // The visual no longer comes from data.
Users may ask the browser for less animation.
const prefersReducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches; if (!prefersReducedMotion) { element.animate(keyframes, options); }
Visuals should not be the only source of meaning.
<figure> <canvas aria-label="Monthly revenue chart"></canvas> <figcaption>Revenue increased over four months.</figcaption> </figure>
Rules that matter
Motion, canvas and drag/drop can improve a product, but only when they stay usable and understandable.
Do not hard-code charts or status when data should drive them.
Canvas, charts and drag/drop need labels or fallback content.
JavaScript should orchestrate, CSS can animate state.
Repeated measurements and writes can hurt performance.
Reduced motion and keyboard use are part of production design.
Mouse, keyboard and touch can behave differently.
Production thinking
Graphics and interaction are where users feel quality immediately. Small implementation choices decide whether the UI feels smooth or chaotic.
Visual UI needs semantic labels, focus management, reduced motion support and alternatives for pointer-only behavior.
Production visual code should be measured, tested on real devices and kept separate from business logic where possible.
Important text should not exist only inside canvas pixels or animation frames.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these before moving to the next graphics and UI lesson.
Senior audit upgrade
Chapter checkpoint
Finish this chapter by turning the lessons into a small practical proof.
Build a small example that combines three lessons from this chapter.
Can you explain the important tradeoff without reading from the page?