JRG
JRG

Reputation: 593

Teechart VCL - how to change Marks border color and mark length at runtime?

I'm using Delphi 10.3-upd 1 with Teechart component .

At run-time I need to put marks for specific points and customize its texts, colors and sizes. I've succeded in changing texts using the following commands :

Chart1.[idxserie].Marks.Item[idxelement].Visible  := True;
Chart1.[idxserie].Marks.Iidxelement]].Font.Color  := clRed;
Chart1.[idxserie].Marks.item[idxelement].Text.Add('My text is here');

now I need to change the color of the line that links the text to the point in the graph curve. In design time, this property is located at :

Editing chart window :

      Series -- myserie1 -
                tab : Marks 
                           -- tab Arrows
                                         -- tab Border 
                                                     tab  -- Format     
                                                                 Button : Color 

How do I access and change the value of this property on run-time ?

I've alreeady tried :

Chart1.[idxserie].Marks.Arrow.Color  := clRed  // ==> nothing changed ! 

This is where I change the property at design time :

enter image description here

In below picture, the dotted red line for some points I want it in different color. When I use Chart1.[idxserie].Marks.Arrow.Color := clRed it changes the color of all points .

enter image description here

I appreciate your support.

Thanks.

Upvotes: 0

Views: 1280

Answers (1)

Reron
Reron

Reputation: 191

The Arrow is global. You can overwrite it yourself using one of the AfterDraw events of Series or Chart.

An example: Creation:

procedure TForm1.FormCreate(Sender: TObject);
begin
  series1.FillSampleValues(5);
  series1.Marks.Visible := true; // A global flag. if false, no Mark will be visible

  series1.Marks[0].Visible := false;
  series1.Marks[1].Visible := true;
  series1.Marks[2].Visible := false;
  series1.Marks[3].Visible := true;
  series1.Marks[4].Visible := false;

  series1.Marks[3].Font.Color := clRed;
  series1.Marks[3].Font.Style := [fsBold];
  series1.Marks[3].Transparent:= true;

  series1.Marks.Arrow.Color    := clGreen;
  series1.Marks.ArrowLength    := 24;
  series1.Marks.Arrow.EndStyle := esFlat;
  series1.Marks.Arrow.Visible  := true;
end;

Now, draw a line on the Chart Canvas:

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
var
  nInx, nX, nY: integer;
begin
  for nInx := 0 to Series1.Count-1 do
    if Series1.Marks[nInx].Font.Color = clRed then
      begin
        nX := Series1.CalcXPos(nInx);
        nY := Series1.CalcYPos(nInx);
        Chart1.Canvas.Pen.Color := clRed;
        Chart1.Canvas.MoveTo(nX, nY);
        Chart1.Canvas.LineTo(nX, nY - series1.Marks.ArrowLength);
      end;
end;

You will get: enter image description here

Upvotes: 0

Related Questions