ChartTheme class

Theme-aware chart styling configuration.

This class provides comprehensive theming for all chart types, including colors, typography, spacing, and visual effects. Themes are designed to work seamlessly with Material Design 3 and support both light and dark modes.

Features

  • Light and dark theme presets
  • Automatic theme inference from Material theme
  • Customizable colors, fonts, and spacing
  • Copy-with method for easy customization
  • Professional gradient color palettes

Example

// Use preset theme
final theme = ChartTheme.light();

// Customize theme
final customTheme = ChartTheme.light().copyWith(
  backgroundColor: Colors.grey[100],
  borderRadius: 24.0,
  xAxisLabelRotation: LabelRotation.diagonalDown, // Rotate X-axis labels
);

// Infer from Material theme
final autoTheme = ChartTheme.fromMaterialTheme(Theme.of(context));

See also:

Constructors

ChartTheme({required Color backgroundColor, required Color textColor, required Color gridColor, required Color axisColor, required List<Color> gradientColors, double shadowElevation = 4.0, double borderRadius = 16.0, bool showGrid = true, bool showAxis = true, bool showLegend = true, bool showTooltip = true, Color cardBorderColor = const Color(0x00000000), Color overlayColor = const Color(0x14000000), Color crosshairColor = const Color(0x66000000), Color tooltipBackgroundColor = const Color(0xFF111827), Color tooltipBorderColor = const Color(0x1FFFFFFF), List<BoxShadow> tooltipShadow = const [BoxShadow(color: Color(0x1A000000), blurRadius: 18, offset: Offset(0, 8), spreadRadius: -6), BoxShadow(color: Color(0x0F000000), blurRadius: 10, offset: Offset(0, 4), spreadRadius: -6)], double gridLineWidth = 1.0, double gridDashWidth = 4.0, double gridDashSpace = 4.0, int xAxisLabelRotation = 0, int yAxisLabelRotation = 0, TextStyle? axisLabelStyle, TextStyle? tooltipStyle, EdgeInsets padding = const EdgeInsets.fromLTRB(40, 20, 20, 40)})
const
ChartTheme.dark()
Create dark theme with enhanced colors.
factory
ChartTheme.fromMaterialTheme(ThemeData theme)
Create theme from Material Theme.
factory
ChartTheme.light()
Create light theme with enhanced colors.
factory

Properties

axisColor Color
final
axisLabelStyle TextStyle?
Text style for axis labels.
final
backgroundColor Color
Card/container surface color (inside dashboard card).
final
borderRadius double
final
cardBorderColor Color
Subtle border color for the chart card.
final
crosshairColor Color
Crosshair color (hover line).
final
gradientColors List<Color>
final
gridColor Color
final
gridDashSpace double
final
gridDashWidth double
final
gridLineWidth double
Grid appearance controls.
final
hashCode int
The hash code for this object.
no setterinherited
overlayColor Color
Optional tinted overlay used for hover/selection highlights.
final
padding EdgeInsets
Padding around the chart content.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shadowElevation double
final
showAxis bool
final
showGrid bool
final
showLegend bool
final
showTooltip bool
final
textColor Color
final
tooltipBackgroundColor Color
Tooltip surface/background color.
final
tooltipBorderColor Color
Tooltip border color.
final
tooltipShadow List<BoxShadow>
Tooltip shadow.
final
tooltipStyle TextStyle?
Text style for tooltips.
final
xAxisLabelRotation int
Rotation angle for X-axis labels in degrees.
final
yAxisLabelRotation int
Rotation angle for Y-axis labels in degrees.
final

Methods

copyWith({Color? backgroundColor, Color? textColor, Color? gridColor, Color? axisColor, List<Color>? gradientColors, double? shadowElevation, double? borderRadius, bool? showGrid, bool? showAxis, bool? showLegend, bool? showTooltip, Color? cardBorderColor, Color? overlayColor, Color? crosshairColor, Color? tooltipBackgroundColor, Color? tooltipBorderColor, List<BoxShadow>? tooltipShadow, double? gridLineWidth, double? gridDashWidth, double? gridDashSpace, int? xAxisLabelRotation, int? yAxisLabelRotation, TextStyle? axisLabelStyle, TextStyle? tooltipStyle, EdgeInsets? padding}) ChartTheme
Creates a copy of this theme with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited