BaseChartPainter class abstract

Base painter for all chart types with common utilities.

This abstract class provides shared functionality for rendering charts, including grid lines, axes, labels, and coordinate transformations. All chart painters should extend this class to inherit these features.

Features

  • Automatic grid and axis rendering
  • Optimized coordinate transformations
  • Efficient repaint detection
  • Batched drawing operations

Example

class MyChartPainter extends BaseChartPainter {
  MyChartPainter({
    required super.theme,
    required super.dataSets,
  });

  @override
  void paint(Canvas canvas, Size size) {
    // Draw grid and axes
    drawGrid(canvas, size, minX, maxX, minY, maxY);
    drawAxes(canvas, size, minX, maxX, minY, maxY);

    // Draw your chart content
    // ...

    // Draw labels
    drawAxisLabels(canvas, size, minX, maxX, minY, maxY);
  }
}

See also:

Inheritance
Implementers

Constructors

BaseChartPainter({required ChartTheme theme, required List<ChartDataSet> dataSets, bool showGrid = true, bool showAxis = true, bool showLabel = true})
Creates a base chart painter.
const

Properties

dataSets List<ChartDataSet>
The data sets to render in the chart.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticsBuilder SemanticsBuilderCallback?
Returns a function that builds semantic information for the picture drawn by this painter.
no setterinherited
showAxis bool
Whether to show axis lines.
final
showGrid bool
Whether to show grid lines.
final
showLabel bool
Whether to show axis labels.
final
theme ChartTheme
The theme to use for styling the chart.
final

Methods

addListener(VoidCallback listener) → void
Register a closure to be notified when it is time to repaint.
inherited
drawAxes(Canvas canvas, Size size, double minX, double maxX, double minY, double maxY) → void
Draw axis lines.
drawAxisLabels(Canvas canvas, Size size, double minX, double maxX, double minY, double maxY, {List<ChartDataSet>? dataSets}) → void
Draw axis labels (optimized with text style caching).
drawGrid(Canvas canvas, Size size, double minX, double maxX, double minY, double maxY) → void
Draw grid lines (optimized with batched operations).
getDataBounds(double getValue(ChartDataPoint), double combine(double, double)) → void
Get data bounds (to be overridden by subclasses).
getNiceMaxY(double maxY, {int targetIntervals = 5}) double
Helper to calculate a "nice" maximum Y value for axis scaling.
hitTest(Offset position) bool?
Called whenever a hit test is being performed on an object that is using this custom paint delegate.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paint(Canvas canvas, Size size) → void
Called whenever the object needs to paint. The given Canvas has its coordinate space configured such that the origin is at the top left of the box. The area of the box is the size of the size argument.
inherited
pointToCanvas(ChartDataPoint point, Size size, double minX, double maxX, double minY, double maxY) Offset
Convert data point to canvas coordinates (optimized).
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that the object notifies when it is time to repaint.
inherited
shouldRebuildSemantics(covariant CustomPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).
inherited
shouldRepaint(covariant BaseChartPainter oldDelegate) bool
Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).
override
toString() String
A string representation of this object.
inherited

Operators

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