Expand description
Chart theme — colors, typography, and shape defaults for chart chrome.
The Theme struct provides all chrome properties used by chart renderers:
colors (axes, grid, text, background), typography (fonts and sizes for
titles, labels, and numeric tick labels), and shape defaults (stroke
weights, dot radii, corner radii, grid styling).
Plain values are written directly into SVG attributes, ensuring compatibility with every SVG renderer (browsers, resvg, Inkscape, etc.).
§Browser theming
When charts are rendered in a browser, a <style> block inside the SVG
maps element classes to CSS custom properties:
.axis-line { stroke: var(--chartml-axis-line) }
.grid-line { stroke: var(--chartml-grid) }CSS specificity means these override the inline attribute defaults, so
consuming apps can set --chartml-axis-line: #9ca3af on a parent element
and charts respond instantly — no re-render needed.
§Server-side rendering
For server-side rendering (e.g. render_to_png()), pass a Theme that
matches your application’s current appearance. The same Theme used
server-side should match the CSS custom properties set browser-side,
ensuring visual parity between both rendering paths.
§Example
use chartml_core::theme::Theme;
// Light mode (default)
let light = Theme::default();
// Dark mode
let dark = Theme::dark();
// Custom theme — `Theme` is `#[non_exhaustive]`, so consumers must
// start from `Theme::default()` or `Theme::dark()` and mutate fields.
// This makes adding new theme fields non-breaking forever.
let mut custom = Theme::dark();
custom.axis_line = "#9ca3af".into();
custom.grid = "#374151".into();Structs§
- Theme
- Chart theme — colors, typography, and shape defaults.
- Zero
Line Spec - Specification for the zero-line (baseline) overlay on value axes.
Enums§
- BarCorner
Radius - Which corners of a bar rect are rounded.
- Grid
Style - Grid line style — controls which gridlines are drawn.
- Text
Transform - Text transform applied to label text (tick labels, axis labels, legend).