Drawing on Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Drawing on Chart

Post by McMClark » Wed Jun 18, 2008 8:10 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jun 19, 2008 9:01 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Post by McMClark » Fri Jun 20, 2008 2:59 pm

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?

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Jun 23, 2008 8:57 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

xxxxxx
Advanced
Posts: 128
Joined: Tue Jun 19, 2007 12:00 am
Location: Russia
Contact:

Post by xxxxxx » Wed Jun 25, 2008 3:32 pm

Since using TeeChart Standard I used to utilize TChart.OnAfterDraw for such persistent drawings. Isn't it not bad?
Regards, Alexander
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Jun 26, 2008 7:59 am

Hi Alexander,

No, using OnAfterDraw event is a good option for custom drawing on the chart.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply