Hi,
I have TPointSeries. The background color of each pointer is given by the value of SeriesColor property. At runtime, I'd like to be able to change the background pointer color of just a few specific points. I've tried playing with ColorEachPoint property but that one sets the pointer colors deliberately. I don't want to change the background color of all pointers, just only a few.
Is there a way how to achieve this in TeeChart VCL 7 Pro?
Thanks in advance,
Ivo
Assign a different color to a specific pointers
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Ivo,
Yes, this can be easily done using the series OnGetPointerStyle event as shown here:
Yes, this can be easily done using the series OnGetPointerStyle event as shown here:
Code: Select all
function TForm1.Series1GetPointerStyle(Sender: TChartSeries;
ValueIndex: Integer): TSeriesPointerStyle;
begin
if (Series1.YValue[ValueIndex] > 100) then Series1.Pointer.Color:=clBlue
else Series1.Pointer.Color:=clRed;
result:=psRectangle;
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Hi, Narcís,
I've tried your code (exactly) and created the following points at runtime:
The expected order of colors would be:
Red
Red
Blue
Blue
Red
Red
However, the actual order of colors I get is:
Red
Red
Red
Blue
Blue
Red
Could you please tell me why? What am I doing wrong?
Thanks!
I've tried your code (exactly) and created the following points at runtime:
Code: Select all
Series1.AddXY(10, 50);
Series1.AddXY(20, 80);
Series1.AddXY(30, 111);
Series1.AddXY(40, 101);
Series1.AddXY(50, 80);
Series1.AddXY(60, 60);
Red
Red
Blue
Blue
Red
Red
However, the actual order of colors I get is:
Red
Red
Red
Blue
Blue
Red
Could you please tell me why? What am I doing wrong?
Thanks!
Hi Ivo,
yes, you're correct, to get correct results you should use similar code to the following :
yes, you're correct, to get correct results you should use similar code to the following :
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.AddXY(10, 50);
Series1.AddXY(20, 80);
Series1.AddXY(30, 111);
Series1.AddXY(40, 101);
Series1.AddXY(50, 80);
Series1.AddXY(60, 60);
Chart1.draw();
end;
function TForm1.Series1GetPointerStyle(Sender: TChartSeries;
ValueIndex: Integer): TSeriesPointerStyle;
begin
if (Series1.YValue[ValueIndex] > 100) then
Series1.ValueColor[ValueIndex]:=clBlue
else
Series1.Valuecolor[ValueIndex]:=clRed;
result:=psRectangle;
end;
Pep Jorge
http://support.steema.com
http://support.steema.com
Hi, Pep!
Series1.ValueColor[] array property is the correct way how to change the data point color at runtime, you're right. Thanks! However, modifying the value of this property form within Series1GetPointerStyle event handler leads to unexpected behavior (at least for me). What I really wanted was to be able to flip the data point color by clicking the pointer with the mouse (i.e. simulating an inclusion/exclusion of certain data point to/from a selection). Finally, I have managed to work it out. Here is an example code for anyone who might be interested:
Series1.ValueColor[] array property is the correct way how to change the data point color at runtime, you're right. Thanks! However, modifying the value of this property form within Series1GetPointerStyle event handler leads to unexpected behavior (at least for me). What I really wanted was to be able to flip the data point color by clicking the pointer with the mouse (i.e. simulating an inclusion/exclusion of certain data point to/from a selection). Finally, I have managed to work it out. Here is an example code for anyone who might be interested:
Code: Select all
type
TForm4 = class(TForm)
Chart1: TChart;
Series1: TPointSeries;
procedure Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
fPointStates: array [0..5] of Boolean;
procedure AddPoint(const X, Y: Double);
function GetPointColor(aIndex: Integer): TColor;
public
end;
procedure TForm4.AddPoint(const X, Y: Double);
var
vIndex: Integer;
begin
vIndex := Series1.AddXY(X, Y);
Assert(vIndex <= High(fPointStates));
Series1.ValueColor[vIndex] := GetPointColor(vIndex);
end;
function TForm4.GetPointColor(aIndex: Integer): TColor;
const
cColors: array [Boolean] of TColor = (clSilver, clBlue);
begin
Result := cColors[fPointStates[aIndex]];
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
AddPoint(10, 50);
AddPoint(20, 80);
AddPoint(30, 111);
AddPoint(40, 101);
AddPoint(50, 80);
AddPoint(60, 60);
end;
procedure TForm4.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fPointStates[ValueIndex] := not fPointStates[ValueIndex];
Series1.ValueColor[ValueIndex] := GetPointColor(ValueIndex);
end;