Page 1 of 1
Drawing on Chart
Posted: Wed Jun 18, 2008 8:10 pm
by 9337074
I would like to enable a user too highlight a part of a graph by draw a box or circle around a section of the chart. I have tried to use the rectangle tool but at runtime the only effect I get is to in act the zoom feature. If the rectangle is the right tool then how do I enable it? I have also tried the annotation tool but I can not enact it.
Posted: Thu Jun 19, 2008 9:01 am
by narcis
Hi McMClark,
I've just replied to the thread you posted in the ActiveX forum:
http://www.teechart.net/support/viewtop ... 1566#31566
Same idea applies to the VCL version.
Posted: Fri Jun 20, 2008 2:59 pm
by 9337074
Thank you for your reply. The code does draw the on the canvas but the drawing does not persist. How do I get it to stay after the user finishes drawing?
Posted: Mon Jun 23, 2008 8:57 am
by yeray
Hi McMClark,
One solution could be drawing a Shape series instead of a canvas rectangle in OnMouseUp event:
Code: Select all
var
Form1: TForm1;
X0, X1, Y0, Y1: Integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
X0 := -1;
Y0 := -1;
Chart1.Zoom.Allow := false;
Chart1.View3D := false;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
X1 := X;
Y1 := Y;
If (X0 <> -1) And (Y0 <> -1) Then
begin
Chart1.Canvas.Brush.Style := bsClear;
Chart1.Canvas.Pen.Color := clBlack;
Chart1.Canvas.Rectangle(X0, Y0, X1, Y1);
Chart1.Draw;
End;
end;
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
X0 := X;
Y0 := Y;
end;
procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var RectSeries: TChartShape;
begin
If (X0 <> -1) And (Y0 <> -1) Then
begin
RectSeries := TChartShape.Create(Self);
Chart1.AddSeries(RectSeries);
with (Chart1.Axes) do
begin
RectSeries.Style := chasRectangle;
RectSeries.X0 := Bottom.CalcPosPoint(X0);
RectSeries.Y0 := Left.CalcPosPoint(Y0);
RectSeries.X1 := Bottom.CalcPosPoint(X1);
RectSeries.Y1 := Left.CalcPosPoint(Y1);
end;
End;
X0 := -1;
Y0 := -1;
end;
Posted: Wed Jun 25, 2008 3:32 pm
by 9047589
Since using TeeChart Standard I used to utilize TChart.OnAfterDraw for such persistent drawings. Isn't it not bad?
Posted: Thu Jun 26, 2008 7:59 am
by narcis
Hi Alexander,
No, using OnAfterDraw event is a good option for custom drawing on the chart.