drawCrossLine method
画交叉线
Implementation
void drawCrossLine(Canvas canvas, Size size) {
// 使用手指位置而不是数据点位置
double x = selectX;
double y = selectY;
// 确保十字线在图表区域内
if (y < mTopPadding) y = mTopPadding;
if (y > size.height - mBottomPadding) y = size.height - mBottomPadding;
// 创建虚线画笔 - 竖线
Paint paintY = Paint()
..color = this.chartColors.hCrossColor // 使用横线相同的颜色确保可见性
..strokeWidth = this.chartStyle.hCrossWidth // 使用合适的宽度,而不是过宽的vCrossWidth
..isAntiAlias = true
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
// 绘制竖线(纵向线) - 使用虚线
_drawDashedLine(
canvas,
Offset(x, mTopPadding),
Offset(x, size.height - mBottomPadding),
paintY,
);
// 创建虚线画笔 - 横线
Paint paintX = Paint()
..color = this.chartColors.hCrossColor // 使用横线颜色
..strokeWidth = this.chartStyle.hCrossWidth // 使用横线宽度
..isAntiAlias = true
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
// 绘制横线 - 使用虚线(只在主图区域绘制)
_drawDashedLine(
canvas,
Offset(0, y),
Offset(size.width, y),
paintX,
);
// 绘制中心点 - 简化设计,只要内圈实心圆圈
canvas.drawCircle(
Offset(x, y),
2.0, // 半径2.0
Paint()
..color = this.chartColors.hCrossColor
..style = PaintingStyle.fill
..isAntiAlias = true,
);
}