How to change the color of each point of TPointSeries

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

How to change the color of each point of TPointSeries

Post by elmec » Sun Mar 16, 2014 4:23 am

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.

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

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

Post by Yeray » Tue Mar 18, 2014 9:38 am

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;
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

Post Reply