drawPolyline method
dynamic
drawPolyline()
Implementation
drawPolyline(double lastPrice, double curPrice, Canvas canvas, double lastX,
double curX) {
// drawLine(lastPrice + 100, curPrice + 100, canvas, lastX, curX, ChartColors.kLineColor);
mLinePath ??= Path();
// if (lastX == curX) {
// mLinePath.moveTo(lastX, getY(lastPrice));
// } else {
//// mLinePath.lineTo(curX, getY(curPrice));
// mLinePath.cubicTo(
// (lastX + curX) / 2, getY(lastPrice), (lastX + curX) / 2, getY(curPrice), curX, getY(curPrice));
// }
if (lastX == curX) lastX = 0; //起点位置填充
mLinePath!.moveTo(lastX, getY(lastPrice));
mLinePath!.cubicTo((lastX + curX) / 2, getY(lastPrice), (lastX + curX) / 2,
getY(curPrice), curX, getY(curPrice));
//画阴影
mLineFillShader ??= LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
tileMode: TileMode.clamp,
colors: [
this.chartColors.lineFillColor,
this.chartColors.lineFillInsideColor
],
).createShader(Rect.fromLTRB(
chartRect.left, chartRect.top, chartRect.right, chartRect.bottom));
mLineFillPaint..shader = mLineFillShader;
mLineFillPath ??= Path();
mLineFillPath!.moveTo(lastX, chartRect.height + chartRect.top);
mLineFillPath!.lineTo(lastX, getY(lastPrice));
mLineFillPath!.cubicTo((lastX + curX) / 2, getY(lastPrice),
(lastX + curX) / 2, getY(curPrice), curX, getY(curPrice));
mLineFillPath!.lineTo(curX, chartRect.height + chartRect.top);
mLineFillPath!.close();
canvas.drawPath(mLineFillPath!, mLineFillPaint);
mLineFillPath!.reset();
canvas.drawPath(mLinePath!,
mLinePaint..strokeWidth = (mLineStrokeWidth / scaleX).clamp(0.1, 1.0));
mLinePath!.reset();
}