Procedure TForm1.Chart1UserDrawnSeries1Draw(ACanvas: TCanvas;
Const ARect: TRect);
Procedure DrawCircle(p: TPoint; AColor: TColor; R: Integer);
Begin
Chart1.Drawer.SetBrushParams(bsSolid, AColor);
Chart1.Drawer.Ellipse(P.x - R, P.y - R, P.x + R, P.y + R);
End;
Function GetColor(y, yref: Integer): TColor;
Begin
If y > yref Then
Result := COLOR_BELOW
Else
Result := COLOR_ABOVE;
End;
Var
i: Integer;
gp: TDoublePoint;
p1, p2, p3: TPoint;
yref: Integer;
x: Integer;
showDataPoints: Boolean;
Begin
showDataPoints := Checkbox1.Checked;
pen.Width := 4;
Chart1.Drawer.Pen := Pen;
yref := Chart1.YGraphToImage(Chart1ConstantLine1.Position);
i := 0;
gp := DoublePoint(Data[i].X, Data[i].Y);
p1 := Chart1.GraphToImage(gp);
If showDataPoints Then Begin
Chart1.Drawer.SetPenParams(psSolid, GetColor(p1.y, yref));
DrawCircle(p1, GetColor(p1.y, yref), RADIUS); // Fix copy paste index error 2->1
End;
For i := 1 To High(Data) Do Begin // draw from second to last point (index of by one correction)
gp := DoublePoint(Data[i].X, Data[i].Y);
p2 := Chart1.GraphToImage(gp);
If (p2.y - yref) * (p1.y - yref) < 0 Then Begin
p3 := Point(Intersect(p1, p2, yref), yref);
Chart1.Drawer.SetPenParams(psSolid, GetColor(p1.y, yref), 2);
Chart1.Drawer.Line(p1, p3);
Chart1.Drawer.SetPenParams(psSolid, GetColor(p2.y, yref), 2);
Chart1.Drawer.Line(p3, p2);
End
Else Begin
Chart1.Drawer.SetPenParams(psSolid, GetColor(p2.y, yref), 2);
Chart1.Drawer.Line(p1, p2);
End;
If showDataPoints Then
DrawCircle(p2, GetColor(p2.y, yref), RADIUS);
p1 := p2;
End;
End;