drawAxes static method
Implementation
static void drawAxes(
Canvas canvas,
ChartContext context, {
int tickCount = 5,
}) {
final axisPaint = context.paintCache.get(
key: 'axis',
color: context.theme.axisColor,
strokeWidth: context.theme.axisStrokeWidth,
);
final bounds = context.bounds;
final viewport = context.viewport;
if (viewport.width <= 0 || viewport.height <= 0) {
return;
}
final textStyle = context.theme.axisTextStyle;
canvas.drawLine(
Offset(bounds.left, bounds.bottom),
Offset(bounds.right, bounds.bottom),
axisPaint,
);
canvas.drawLine(
Offset(bounds.left, bounds.top),
Offset(bounds.left, bounds.bottom),
axisPaint,
);
for (var i = 0; i <= tickCount; i++) {
final t = i / tickCount;
final dataX = viewport.minX + viewport.width * t;
final canvasX = bounds.left + bounds.width * t;
_drawLabel(
canvas,
_formatValue(dataX),
Offset(canvasX, bounds.bottom + 4),
textStyle,
align: TextAlign.center,
);
final dataY = viewport.minY + viewport.height * t;
final canvasY = bounds.bottom - bounds.height * t;
_drawLabel(
canvas,
_formatValue(dataY),
Offset(bounds.left - 4, canvasY),
textStyle,
align: TextAlign.right,
);
}
drawAxisTitles(canvas, context);
}