Skip to content
HDCharts

Style Defaults

Every chart takes one style object built with its *ChartDefaults factories. These rules keep the defaults the same across charts. Follow them when adding a chart, a style block, or a default.

Every default value lives in StyleDefaults in charts-core, including the chart-specific ones. Factories read their defaults from it and never repeat a literal, so the same element cannot differ between charts. The tables below list what it holds.

Factories

A chart's *ChartDefaults object has one factory per style block, plus style(). Users write every call against one object:

BarChartDefaults.style(
    axis = BarChartDefaults.axis(xLabels = BarChartDefaults.xLabels(maxCount = 4)),
)
  • Nesting stops at three levels: style, then a block, then axis labels. Axis labels are the only third level, and all Cartesian charts share them as AxisLabelStyle.
  • Every block gets a factory on the chart's own object, even when the block type is shared. HistogramChartDefaults forwards grid, axis, xLabels, yLabels and selection to BarChartDefaults, and its range keeps a zero minimum.
  • Forwarding factories repeat the default parameters, because Kotlin cannot forward them. Both read the same StyleDefaults value, and a test compares the two objects (BarStyleDefaultsTest).

Colors

Default colors come from MaterialTheme.colorScheme roles at full opacity, so they follow the app's theme in light and dark mode. Do not lower the alpha of a theme color, and do not check isSystemInDarkTheme(): the app's theme can differ from the system setting.

ElementRoleCharts
Series (bars, lines, fills, slices)primary, or a palette from itAll
PointstertiaryLine, radar (with colorSameAsLine = false)
Axis labelsonSurfaceVariantBar, histogram, line, stacked bar, stacked area, radar
TitleonSurfaceAll
Grid linesoutlineVariantBar, histogram, radar (rings and spokes)
Axis linesoutlineBar, histogram, line
Selection lineonSurfaceBar, histogram, line, stacked bar, stacked area
Selection markertertiaryLine
Slice bordersurfacePie

Selection indicators draw on top of series marks. A selection default must never use the series role (primary or its palette), or it disappears over the selected mark.

Sizes

Sizes are Dp, so they scale with screen density. Point and marker sizes are radii.

ElementDefaultCharts
Grid and axis lines1.dpBar, histogram, line, radar
Selection line1.dpBar, histogram, line, stacked bar, stacked area
Slice border1.dpPie
Series line2.dpLine (strokeWidth), radar (lineWidth)
Points4.dpLine, radar (data points)
Selected point5.dp (selection.pointSize)Line, radar
Touch marker on the line3.dp (selection.markerSize)Line
Gap between an axis and its labels10.dpBar, histogram, line, stacked bar, stacked area, radar
Radar label clamp margin6.dp, only for a label that does not fitRadar
Bar spacing10.dp, 0.dp on histogramBar, histogram, stacked bar
Minimum bar width10.dpBar, histogram, stacked bar
Container padding15.dpAll

Text

ElementDefaultCharts
Title20.sp, ExtraBoldAll
Axis labels11.spBar, histogram, line, stacked bar, stacked area, radar

Alpha

Chart color alpha defaults to 1f, so the colors a user passes are drawn exactly as given. Users who want a softer look pass alpha themselves.

SettingDefaultCharts
Series alpha1fBar, histogram, line, pie, stacked bar, stacked area
Polygon fillAlpha0.25fRadar
Selection unselectedAlpha0.7fBar, histogram, stacked bar, stacked area, radar
Selection unfocusedSeriesAlpha0.35fRadar

Radar is the one exception to full-opacity fills. Radar polygons overlap each other and the grid, so a solid fill would hide the series behind it.

Selection dimming applies only while something is selected and multiplies the series alpha; it does not change the resting colors. unfocusedSeriesAlpha is lower than unselectedAlpha, because translucent radar fills barely change at 0.7f.

Do not add a default mark that draws in the series color on top of its own series, such as the removed stacked-area boundary line. At full opacity it cannot be seen.

Chart-specific defaults

SettingDefaultCharts
Grid steps4Bar, histogram, radar
RangeFitted to the data, minimum 0.0 on histogramBar, histogram, line
Axis label maxCountnull (as many as fit)Bar, histogram, line, stacked bar, stacked area
Curved lines (bezier)true on line, false on stacked areaLine, stacked area
Points visiblefalse; the selected point is still drawnLine, radar
Radar axis labels visibletrue; the web shrinks to leave room for themRadar
Radar points use line colortrueRadar
Donut hole0f (full pie)Pie
Zoom controls visibletrueBar, histogram, line, stacked bar, stacked area
Legend visibletrueLine, pie; radar only with more than one series

Invalid values

Style values are never rejected; each chart draws a clamped copy of its style. Style Clamping describes the rules, and Validation Errors lists what is still an error.

Selection

A thin line cannot contrast with both the background and every bar color, so bar, histogram, and stacked bar charts let the selected bar mark the selection. The other bars dim to unselectedAlpha, and the selection line is drawn only over the background.

Stacked area follows the same rule. A column one data step wide around the selected point keeps full color, the rest of the stack dims, and the selection line stops at the top of the stack.

Radar has no selection line. Dragging selects an axis, and its per-axis marks are the points: the data points and labels of the other axes dim to unselectedAlpha. Polygons stay whole, because their shape is what a radar chart shows. Tapping a series outline focuses the series and fades the others to unfocusedSeriesAlpha.