Problem with moving Marks

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Problem with moving Marks

Post by rackerson » Wed Nov 29, 2006 11:16 pm

Delphi 6 Enterprise, TeeChart 7.07

I have been asked to provide a way for the users to control where the Marks are displayed on a chart. I checked through the forum and found the following link: http://www.teechart.net/support/viewtopic.php?t=2230 offered as advice on doing this. Unfortunately, I seem to have missed something because once the marks start to move, the display becomes very eratic. The following is my code:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  APosition:TSeriesMarkPosition;
begin
  APosition:=TSeriesMarkPosition.Create;
  with Chart1 do
  try
    for i:=0 to Series1.Count-1 do
    begin
      APosition.Custom:=True;
      APosition.LeftTop.X:=Series1.Marks.Positions[i].LeftTop.X;
      APosition.LeftTop.Y:=Series1.Marks.Positions[i].LeftTop.Y-35;
      Series1.Marks.Positions[i]:=APosition;
    end;
  finally
    APosition.Free;
  end;
  Chart1.Invalidate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(6);
  Chart1.Draw;
end;
From what I understand, this should simply move the marks UP 35 pixels each time my Button1 is clicked.

Before the button is clicked, my chart looks like:
Image

Normal enough. However, when I click the button the chart becomes:
Image

Kind of a disaster. For some reason,
  • 1. my marks have become transparent, although the Transparent property is FALSE
    2. my mark text has become centered on the associated symbol
    3. the line between my mark text and the chart has moved, now starting from the upper left corner of my chart background
    4. the marks themselves did not move as expected. Rather than move UP, they kind of moved outward from some centerpoint.
Then I tried clicking the button one more time to see what would happen. This is the result:
Image
This time, the marks DID move up 35 pixels, as I originally expected. If I keep clicking the button, the marks will now keep moving up until they leave the screen.

But I have to ask, WHY did all the rest of those items happen? Even if the marks themselves did not move to the correct locations, shouldn't the line that was associated with them have moved WITH THEM to their new location?

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 Nov 30, 2006 9:30 am

Hi rackerson,

It works fine with pie series using the second approach told at the thread you pointed:

Code: Select all

procedure TForm9.Button1Click(Sender: TObject);
var i: Integer;
begin

  for i:=0 to Series1.Count-1 do
  begin
    With Series1.Marks.Positions.Position[i] do
    Begin
      Custom:=True;
      LeftTop.Y := LeftTop.Y - 35;
    end;
  end;
  Series1.Marks.Arrow.Visible:=false;
  Series1.Repaint;

end;

procedure TForm9.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(6);
  Chart1.Draw;
end;
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

rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Post by rackerson » Thu Nov 30, 2006 4:28 pm

Thanks for the revised code. It *mostly* works as expected (your example removes the line connecting the chart and the mark text). With the addition of updating the ArrowTo property of each position, I am able to get the line to stay connected to the mark.

I now have a new question related to selecting / moving marks. In addition to being able to relocate marks on a chart (which I need to be able to do for Line, Bar, and Pie series - I assume your sample code will work for each), I have additionally been given the request / requirement that the user be able to click on a mark and drag it to its new location.

Outside of adding code to the Chart's OnMouseMove event and checking the mouse's position against the dimensions of every mark (which I assume would be a bit of a performance hit), is there a way to tell when a mouse is over a mark?

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 Nov 30, 2006 4:30 pm

Hi rackerson,

It's much easier, there's Drag Marks tool for this. You'll find an example of the tool at All Features\Welcome!\Tools\Drag Marks in the features demo. You'll find the demo at TeeChart's program group.
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

rackerson
Newbie
Newbie
Posts: 22
Joined: Mon Mar 08, 2004 5:00 am
Location: Edison, New Jersey USA

Post by rackerson » Thu Nov 30, 2006 5:28 pm

Thanks for the tip. Yes, this looks MUCH easier. However, there is still an issue.

While the DragMarks tool allows marks to be dragged around and the line stays connected to the mark, unusual behavior happens when the form gets resized.

If you run your demo and move any marks and then maximize the form, you will see that any marks that have been moved do NOT get repositioned when the form resizes. All marks that have not been moved DO correctly reposition.

Is there a property to set to get a moved mark to respond the same way a non-moved mark does?

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

Post by Narcís » Fri Dec 01, 2006 8:11 am

Hi rackerson,

To achieve that you should set the marks position to a relative position to the ChartRect, axes, series point, ... And redraw the chart (Chart1.Draw) after resizing the form.
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