Point series and marks text position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Point series and marks text position

Post by johnnix » Sat Apr 27, 2019 7:45 am

Hello,

I am using the latest TChart version and I have trouble to adjust marks text placement when YMandatory is set to false. If I set YMantatory to true then then I can control the margin between the mark point and text by adjusting the arrow length. How can I adjust the text position and what exactly is the YMantatory property?

Regards
Attachments
Project1.zip
(5.03 KiB) Downloaded 1052 times

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

Re: Point series and marks text position

Post by Yeray » Tue Apr 30, 2019 9:26 am

Indeed the ArrowLength is only applied when YMandatory is true:

Code: Select all

Procedure TCustomSeries.DrawMark( ValueIndex:Integer; Const St:String;
                                  APosition:TSeriesMarkPosition);
  //...
  if YMandatory then
     Marks.ApplyArrowLength(APosition);
//...
This was probably made to avoid problems. I see it's like this since TeeChart v6 (in 2003).

The YMandatory property controls whether the series is "horizontal" or "vertical".
Look at the SetHorizontal method:

Code: Select all

procedure TChartSeries.SetHorizontal;
begin
  MandatoryValueList:=XValues;
  NotMandatoryValueList:=YValues;
  YMandatory:=False;
end;
The SetHorizontal method is only called for the "horizontal" series (such as THorizLineSeries and THorizAreaSeries). Otherwise, the YMandatory property is initialized at the TChartSeries constructor:

Code: Select all

Constructor TChartSeries.Create
//...
  FX:=TChartValueList.Create(Self,TeeMsg_ValuesX);
  FX.FOrder:=loAscending;
  NotMandatoryValueList:=FX;

  FY:=TChartValueList.Create(Self,TeeMsg_ValuesY);
  MandatoryValueList:=FY;
  YMandatory:=True;
//...
Why are you manually setting YMandatory to false?
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

johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Re: Point series and marks text position

Post by johnnix » Thu May 02, 2019 7:07 am

Hello Yeray,

I try to create a band between 2 PointSeries, for each PointSeries I create LineSeries that is a smoothing function of the associated PointSeries. After trial and error I found out that setting the Y mandatory to false helps create "correct" smoothing lines :)

Thank you very much for the support!

Regards

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

Re: Point series and marks text position

Post by Yeray » Mon May 06, 2019 7:12 am

Hello,

Check out this simple example:
Project1_2019-05-06_09-10-21.png
Project1_2019-05-06_09-10-21.png (26.71 KiB) Viewed 16328 times
I only had to exchange the X and Y values between the source point series and the horizline series:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var point: array[0..1] of TPointSeries;
    horizLine: array[0..1] of THorizLineSeries;
    i, j: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;
  Chart1.Gradient.Visible:=False;
  Chart1.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;

  Chart1.Axes.Left.Increment:=1;

  for i:=0 to 1 do
  begin
    point[i]:=TPointSeries(Chart1.AddSeries(TPointSeries));

    with point[i] do
    begin
      Pointer.Size:=3;
      Marks.Visible:=True;
      Marks.Transparent:=True;
      Marks.ArrowLength:=10;
      Marks.Arrow.Visible:=False;

      AddXY(random*10-5, 0);
      for j:=1 to 9 do
        AddXY(XValue[j-1] + random*10-5, j);
    end;

    horizLine[i]:=THorizLineSeries(Chart1.AddSeries(THorizLineSeries));
    with horizLine[i] do
    begin
      Smoothed:=True;
      Color:=point[i].Color;
      for j:=0 to point[i].Count-1 do
        AddXY(point[i].XValue[j], point[i].YValue[j]);
    end;
  end;

  with TSeriesBandTool(Chart1.Tools.Add(TSeriesBandTool)) do
  begin
    Brush.BackColor:=clGray;
    Transparency:=70;

    Series:=horizLine[0];
    Series2:=horizLine[1];
  end;
end;
Note I've used the Smoothed property of the LineSeries above. If you want to use a SmoothingFunction (ie to control the Factor), you'll need two extra HorizLine series. Here an example (I'm not showing a screenshot because it looks exactly as above):

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var point: array[0..1] of TPointSeries;
    horizLine: array[0..1] of THorizLineSeries;
    smoothLine: array[0..1] of THorizLineSeries;
    smoothFunc: array[0..1] of TSmoothingFunction;
    i, j: Integer;
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;
  Chart1.Gradient.Visible:=False;
  Chart1.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;

  Chart1.Axes.Left.Increment:=1;

  for i:=0 to 1 do
  begin
    point[i]:=TPointSeries(Chart1.AddSeries(TPointSeries));

    with point[i] do
    begin
      Pointer.Size:=3;
      Marks.Visible:=True;
      Marks.Transparent:=True;
      Marks.ArrowLength:=10;
      Marks.Arrow.Visible:=False;

      AddXY(random*10-5, 0);
      for j:=1 to 9 do
        AddXY(XValue[j-1] + random*10-5, j);
    end;

    horizLine[i]:=THorizLineSeries(Chart1.AddSeries(THorizLineSeries));
    with horizLine[i] do
    begin
      //Smoothed:=True;
      Color:=point[i].Color;
      for j:=0 to point[i].Count-1 do
        AddXY(point[i].XValue[j], point[i].YValue[j]);

      Active:=False;
    end;

    smoothFunc[i]:=TSmoothingFunction.Create(Self);
    smoothFunc[i].Factor:=10;
    smoothLine[i]:=THorizLineSeries(Chart1.AddSeries(THorizLineSeries));
    with smoothLine[i] do
    begin
      Color:=horizLine[i].Color;
      SetFunction(smoothFunc[i]);
      DataSource:=horizLine[i];
    end;
  end;

  with TSeriesBandTool(Chart1.Tools.Add(TSeriesBandTool)) do
  begin
    Brush.BackColor:=clGray;
    Transparency:=70;

    Series:=smoothLine[0];
    Series2:=smoothLine[1];
  end;
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

johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Re: Point series and marks text position

Post by johnnix » Fri May 10, 2019 7:58 am

Thank you, I will take a closer look!

Post Reply