Page 1 of 1

How to change the color of each point of TPointSeries

Posted: Sun Mar 16, 2014 4:23 am
by 16566869
We know that TPointSeries provides Marks->Item->Color property
for changing the color of each marks.

But how to change the color of each point of TPointSeries...
I cannt find something like Pointer->Item->Color..
only the property Pointer->Color provided for changing the color of all pointers.

Re: How to change the color of each point of TPointSeries

Posted: Tue Mar 18, 2014 9:38 am
by yeray
Hello,

You can use the Add(Value ) override to add your values to the series specifying the label (it can be empty '' if you want) and the color. Ie:

Code: Select all

uses FMXTee.Series;

Function RGBA(const r,g,b,a:Integer):TColor;
begin
  {$IFDEF FMX}
  TAlphaColorRec(result).A:=a;
  TAlphaColorRec(result).R:=r;
  TAlphaColorRec(result).G:=g;
  TAlphaColorRec(result).B:=b;
  {$ELSE}
  result := (r or (g shl 8) or (b shl 16) or (a shl 24));
  {$ENDIF}
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  with Chart1.AddSeries(TPointSeries) as TPointSeries do
  begin
    for i:=0 to 24 do
      Add(Random(100), '', RGBA(Random(255), Random(255), Random(255), Random(255)));
  end;
end;
Alternatively, once you have the series populated, you can manipulate the ValueColor array of the series. Ie:

Code: Select all

uses FMXTee.Series;

Function RGBA(const r,g,b,a:Integer):TColor;
begin
  {$IFDEF FMX}
  TAlphaColorRec(result).A:=a;
  TAlphaColorRec(result).R:=r;
  TAlphaColorRec(result).G:=g;
  TAlphaColorRec(result).B:=b;
  {$ELSE}
  result := (r or (g shl 8) or (b shl 16) or (a shl 24));
  {$ENDIF}
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  with Chart1.AddSeries(TPointSeries) as TPointSeries do
  begin
    FillSampleValues;

    for i:=0 to Count-1 do
      ValueColor[i]:=RGBA(random(255),random(255),random(255),random(255));
  end;
end;