Course contentsShow
← Web Development
Lesson 2602 of 2,98247. Data VisualizationFree lesson

SVG Basic Shapes for Charts

Master rect, circle, ellipse, line, polyline, and polygon elements for building chart components.

SVG Basic Shapes for Charts

You'll learn how to use SVG's six primitive shape elements to construct the fundamental building blocks of data visualizations.

The Shape Toolkit

Think of SVG shapes as a drafting kit for data viz—each element is purpose-built for different chart components. You already understand SVG fundamentals; now we're zooming in on the specific shapes that become bars, points, lines, and slices in your charts.

The Six Essential Shapes

<rect> creates rectangles—your go-to for bar charts, heatmaps, and treemaps. You define x, y, width, and height. Perfect for representing categorical data as columns or rows.

<circle> and <ellipse> draw circular shapes. <circle> uses cx, cy (center coordinates), and r (radius)—ideal for scatter plots and bubble charts. <ellipse> adds rx and ry for stretched circles when you need oval markers.

<line> draws straight segments between two points (x1, y1 to x2, y2). Use these for grid lines, reference lines, or connecting data points.

<polyline> connects multiple points with a continuous stroke but no fill—perfect for line charts. You specify coordinates as a space-separated list: points="0,50 100,30 200,80".

<polygon> works like <polyline> but automatically closes the shape, creating filled areas. This is your tool for radar charts, pie slices (combined with arcs), or area charts.

Why These Matter

Each shape is optimized for performance and simplicity. A bar chart might use dozens of <rect> elements, while a line chart uses one <polyline> with hundreds of points. Understanding which primitive fits your data structure makes your visualization code cleaner and faster.

Key Takeaway: Master these six SVG primitives—rect, circle, ellipse, line, polyline, and polygon—and you have everything needed to build the visual components of any chart type from the ground up.