How to change Mark position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
droid
Newbie
Newbie
Posts: 5
Joined: Mon Jun 27, 2005 4:00 am

How to change Mark position

Post by droid » Tue Oct 10, 2006 7:36 am

Hi,

Is it possible to change the Mark position at all?

I tried to do that using Serie.Marks.Positions.Position[ind].LeftTop.X := somevalue; but always got access violation error message.

Thanks in advance,
droid

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

Post by Narcís » Tue Oct 10, 2006 7:49 am

Hi droid,

Yes, this is possible. Please read this old message explaining how to do that.
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

droid
Newbie
Newbie
Posts: 5
Joined: Mon Jun 27, 2005 4:00 am

Post by droid » Tue Oct 10, 2006 11:45 pm

narcis wrote:Hi droid,

Yes, this is possible. Please read this old message explaining how to do that.
Hi Narcis,

thanks a lot, that code helped me a lot but I still have troubles.
I can feel it is a timing ussue.

I need to display marks in GanttChart not in the middle of the bar(default) but at the end of it.

I use the following code to achieve this:

Gantt := TGanttSeries(Chart1.Series[0]);
For ind := 0 to Gantt.Count-1 do
begin
Gantt.Marks.Positions.Position[Ind].Custom := true;
Gantt.Marks.Positions.Position[Ind].LeftTop.X := Gantt.CalcXPosValue(Gantt.EndValues[ind]);
end;
Gantt.Repaint;

It works as expected but only if I, say, have a button on the form and invoke the code above on ButtonClick event.

My idea is to do that automatically every time chart gets re-drawn.
So I put the code above into Chart1AfterDraw event. But it will not work that way because mark will appear in a wrong place!

Can you give me any idea what I'm doing wrong?

thanks,
droid

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

Post by Narcís » Wed Oct 11, 2006 7:33 am

Hi droid,

If you use the code in the OnAfterDraw event you can add a Chart1.Draw; call at the end in the OnFormCreate event so that the chart is forced to be repainted and thus marks properly positioned.
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

droid
Newbie
Newbie
Posts: 5
Joined: Mon Jun 27, 2005 4:00 am

Post by droid » Thu Oct 12, 2006 12:22 am

narcis wrote:Hi droid,

If you use the code in the OnAfterDraw event you can add a Chart1.Draw; call at the end in the OnFormCreate event so that the chart is forced to be repainted and thus marks properly positioned.
That's exactly the way I'm doing it!
I build chart, then do chart.draw but it won't work !

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 Oct 13, 2006 10:36 am

Hi droid,

Could you please send us an example we can run "as-is" to reproduce the problem here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Thanks in advance.
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Thu Jan 25, 2007 4:38 pm

How would you move a mark that was just added? I add lines to a series whos marks need moved a calculated distance away from the add line each time one is added. If I place similar code like that above in a button event, it works fine..but when I try to place it in OnAfterDraw, I get an access violation error. Have also tried sFLines.AfterDrawValue, OnAfterAdd, OnGetMarkText, etc.

procedure TForm1.MoveLineMark(Num: integer);
begin
if Num > sFLines.Count-1 then exit;
with sFLines.Marks.Positions[Num] do begin
Custom:=True;
// LeftTop.X:=.LeftTop.X;
LeftTop.Y:=LeftTop.Y-5;
// sFlines.Repaint;
end;
end;

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 Jan 26, 2007 8:52 am

Hi pssdelphi,

Have you seen the example I posted in the old message I linked on my 10th October 2006 post?
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Fri Jan 26, 2007 2:19 pm

Yes, that and every other post I could find on the subject. The trouble is that the posts I could find on the topic address the problem mostly based upon having a set series loaded or created at the inital start of the program., ie, placing the Draw method in OnFormCreate. My problem is dealing with marks that are being added to the series dynamically as the user decides to add them. When I try triggering the code OnAfterDraw and other events (as listed in my question) I get an access voilation error. How would I update the position of a mark of a newly added point in a series without getting an access violation?

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 Jan 26, 2007 2:49 pm

Hi pssdelphi,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Fri Jan 26, 2007 4:23 pm

Sent

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

Post by Narcís » Mon Jan 29, 2007 11:15 am

Hi pssdelphi,

Thanks for the example project.

The Access Violation occurs because MoveLineMark is called before the chart is refreshed after new data is added to the series. You can solve this problem adding a TChart.Refresh call:

Code: Select all

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart;
  Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  xs, ys: double;
begin
  xs:=Series1.XScreenToValue(x);
  ys:=Series1.YScreenToValue(y);
  Series1.AddXY(xs,ys);
  Inc(NumAdded);
//  if NumAdded > 0 then
  Chart1.Refresh;
    MoveLineMark(Series1.Count-1);
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Mon Jan 29, 2007 4:49 pm

That does prevent the error, but the results are very erratic. What the sample program I sent was intended to do was to move the mark of the newly added point. What it seems to be doing is when you add the first point, the mark for that point doesnt change from origional position. When you add a 2nd point, the mark of the previous point moves and this continues till you get to the 8-10th added point, then things get really wierd. Also, once a point mark gets moved it seems disconnected from the point, because if you scroll the chart after a point is added the moved mark is fixed in position and doesnt move with the point.

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
xs, ys: double;
ja: integer;
begin
xs:=Series.XScreenToValue(x);
ys:=Series.YScreenToValue(y);
ja:=Series1.AddXY(xs,ys);
Chart1.Refresh;
MoveLineMark(ja);
end;

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

Post by Narcís » Tue Jan 30, 2007 1:04 pm

Hi pssdelphi,

It is not working because you are not repainting the series after marks positions are changed, as my 21st April 2005 post in the thread I mentioned.

Code: Select all

procedure TForm1.MoveLineMark(Num: integer);
begin
  with Series1 do begin
    if Num > Count-1 then exit;

    with Marks.Positions[Num] do begin
      Custom:=True;
      LeftTop.Y:=LeftTop.Y-10;
    end;

    Repaint;
  end;
  
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Tue Jan 30, 2007 2:22 pm

That does help with the first part of what was going on but if you scroll the chart at any time or add about 10 or so points things still go wacky.

Post Reply