Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

Centered text

Public visualization

Centered text

0 stars0🌍 Public
MMarta
Last edited Oct 2, 2024
Created on Sep 27, 2024

This example shows how to create a static SVG graphic with a single, perfectly centered text label against a teal background. The code uses D3’s `select` method to append an SVG element to the body and sets its dimensions via `viewBox`. It then appends a `text` element, positions it at the midpoint of the SVG’s width and height, and applies the `text-anchor` and `dominant-baseline` attributes to achieve both horizontal and vertical centering. The text is styled with a 34px font size.

AI-generated description

Trying to learn how this thing works.

Comments

Sign in to join the discussion.

ISC Licensed