Page 1 of 2

How to change Mark position

Posted: Tue Oct 10, 2006 7:36 am
by 9237496
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

Posted: Tue Oct 10, 2006 7:49 am
by narcis
Hi droid,

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

Posted: Tue Oct 10, 2006 11:45 pm
by 9237496
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

Posted: Wed Oct 11, 2006 7:33 am
by narcis
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.

Posted: Thu Oct 12, 2006 12:22 am
by 9237496
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 !

Posted: Fri Oct 13, 2006 10:36 am
by narcis
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.

Posted: Thu Jan 25, 2007 4:38 pm
by 9339638
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;

Posted: Fri Jan 26, 2007 8:52 am
by narcis
Hi pssdelphi,

Have you seen the example I posted in the old message I linked on my 10th October 2006 post?

Posted: Fri Jan 26, 2007 2:19 pm
by 9339638
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?

Posted: Fri Jan 26, 2007 2:49 pm
by narcis
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.

Posted: Fri Jan 26, 2007 4:23 pm
by 9339638
Sent

Posted: Mon Jan 29, 2007 11:15 am
by narcis
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;

Posted: Mon Jan 29, 2007 4:49 pm
by 9339638
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;

Posted: Tue Jan 30, 2007 1:04 pm
by narcis
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;

Posted: Tue Jan 30, 2007 2:22 pm
by 9339638
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.