Marks plus Scroll

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Marcelo
Newbie
Newbie
Posts: 7
Joined: Sat Oct 04, 2003 4:00 am
Location: Brazil

Marks plus Scroll

Post by Marcelo » Wed Dec 08, 2004 8:15 pm

Hi,

I'm tryng to define manually the marks position in my chart ( TBarSeries ). I'm having troubles when I do a horizontal scrolling in the chart. The marks don't 'scroll' with the bars. This is the code :

procedure TfSGEIS_SHOW.ChartAfterDraw(Sender: TObject);
Var i,j:Integer;
lAlterna : Boolean;
begin
lAlterna := False;
if true then //just testing
begin
For i:= 0 to Chart.SeriesCount-1 do
begin
If Chart.Series.Marks.Positions[0] <> Nil then
begin
For j:=0 To Chart.Series.Marks.Positions.Count-1 do
begin
With Chart.Series.Marks.Positions[j] do
begin
Custom:=true;
If lAlterna then
LeftTop.Y:= LeftTop.Y + 10
else
LeftTop.Y:= LeftTop.Y - 10
end
lAlterna := Not lAlterna;
end;
end
end;
lFirst := True;
Chart.Refresh;
end

end;

What can I do to solve this ?

Regards

Marcelo ( Brazil )

Pep
Site Admin
Site Admin
Posts: 3274
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Dec 09, 2004 12:05 am

Hi Marcelo,

you can use similar code to the following :

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  DoAlignMarks(Series1);
end;

procedure TForm1.DoAlignMarks(Series: TBarSeries);
var sx, sy : integer;
    i      : integer;
begin
      for i:=0 to Series.Count-1 do
      begin
        sx := Series.CalcXPos(i);
        sy := Series.CalcYPos(i);
        With Series.Marks.Positions.Position[i] do
        Begin
          Custom:=True;
          LeftTop.x := sx;
          LeftTop.y := sy - 12;
        end;
      end;
  Series.Repaint;
end;

Marcelo
Newbie
Newbie
Posts: 7
Joined: Sat Oct 04, 2003 4:00 am
Location: Brazil

Post by Marcelo » Thu Dec 09, 2004 3:52 pm

Thanks Pep, your code solve my problem :) , but I didn't get move the arrows. What I need to do ? It's possible to hide those arrows ?

tks.

Marcelo
Pep wrote:Hi Marcelo,

you can use similar code to the following :

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  DoAlignMarks(Series1);
end;

procedure TForm1.DoAlignMarks(Series: TBarSeries);
var sx, sy : integer;
    i      : integer;
begin
      for i:=0 to Series.Count-1 do
      begin
        sx := Series.CalcXPos(i);
        sy := Series.CalcYPos(i);
        With Series.Marks.Positions.Position[i] do
        Begin
          Custom:=True;
          LeftTop.x := sx;
          LeftTop.y := sy - 12;
        end;
      end;
  Series.Repaint;
end;

Pep
Site Admin
Site Admin
Posts: 3274
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Tue Dec 14, 2004 7:24 am

Hi Marcelo,

yes, you can hide them using :
Series.Marks.Arrow.Hide;
or set the ArrowFrom and ArrowTo values.

Marcelo
Newbie
Newbie
Posts: 7
Joined: Sat Oct 04, 2003 4:00 am
Location: Brazil

Post by Marcelo » Wed Dec 22, 2004 2:03 pm

Pep wrote:Hi Marcelo,

yes, you can hide them using :
Series.Marks.Arrow.Hide;
or set the ArrowFrom and ArrowTo values.
Hi Pep

It's worked. Thanks.
One more question : In code below, I have to call the Chart.refresh method to new marks positions work. Only using the Repaint didn't work.
But when I use the Refresh method in Windows 98 workstations, a GPF happens (Stack Overflow). What can I do ?

Code: Select all

procedure TfSGEIS_SHOW.ChartAfterDraw(Sender: TObject);
Var i:Integer;
    lAlterna,lAlternaOld : Boolean;
begin
   For i:= 0 to Chart.SeriesCount-1 do
     begin
        DoAlignMarks(TBarSeries(Chart.Series[i]),lAlterna);
        lAlterna := Not lAlterna
     end;
   Chart.Refresh;
end;


procedure TfSGEIS_SHOW.DoAlignMarks(Series: TBarSeries;var lAlterna : Boolean);
var sx, sy : integer;
    i      : integer;
begin

   if (Series.ClassName <> 'TBarSeries') or (Series.MultiBar = mbStacked)  or  (Series.MultiBar = mbStacked100) then
      Exit;

   for i:=0 to Series.Count-1 do
      begin

        sx := Series.CalcXPos(i);
        sy := Series.CalcYPos(i);

        With Series.Marks.Positions.Position[i] do
          If (Series.Marks.Positions.Position[i] <> nil) then
              Begin
                try
                Series.Marks.Arrow.Visible := True;

                Custom:=True;
                Series.Marks.Arrow.Color := clBlack;
                ArrowFrom.x := sx+12;
                ArrowFrom.y := sy;
                ArrowTo.x := ArrowFrom.x;

                LeftTop.x := sx;
                If lAlterna then
                  begin
                    LeftTop.Y:= sy - 35;
                    ArrowTo.y := sy-22;
                  end
                else
                  begin
                    LeftTop.Y:= sy - 20;
                    ArrowTo.y := sy-10;
                  end
                except
                end;
              end
          else
             Break;
      end;
  Series.Repaint;      
end;

Pep
Site Admin
Site Admin
Posts: 3274
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Dec 23, 2004 10:11 am

Hi Marcelo,

it should work without the Refresh, also it's not a good place to run it. Better to place it in hte DoAlignMarks procedure. How can I reproduce what the results you're getting ? Could you please post a simple example in the steema.public.attachments newsgroup so I can see what you refer ?

Post Reply