Page 1 of 1
How to give points different style
Posted: Tue May 17, 2016 8:03 am
by 16576425
Hi
I am adding data to a TPoint3DSeries using the following code
Code: Select all
Chart1.FreeAllSeries(nil);
mySerie:=TPoint3DSeries.Create(self);
mySerie.Clear;
Chart1.AddSeries(mySerie);
mySerie.ColorEachPoint := true;
for i:=1 to Data.NrOfColumns do
begin
mySerie.AddXY(xval,Yval,labelname,Colors[i]);
end;
After this we can change some attributes of the point object individually. But not the point style.
I wish to give each point its own style (circle, Triangle, Star, etc.). Can you provide sample code for how to do that?
Thanks.
Re: How to give points different style
Posted: Tue May 17, 2016 11:00 am
by yeray
Hello,
The easiest way would be using the OnGetPointerStyle event.
You could have an array of TSeriesPointerStyle with the same size of your series values arrays. Ie:
Code: Select all
var mySeriePStyles: Array of TSeriesPointerStyle;
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
//... somewhere after populating the series
setLength(mySeriePStyles, mySerie.Count);
for i:=0 to mySerie.Count-1 do
mySeriePStyles[i]:=TSeriesPointerStyle(Round(random*16));
//...
end;
Then, you could OnGetPointerStyle event to use that array:
Code: Select all
function TForm1.mySerieGetPointerStyle(Sender:TChartSeries;
ValueIndex:Integer): TSeriesPointerStyle;
begin
result:=mySeriePStyles[ValueIndex];
end;
Don't forget to declare the signature of the event and assign it to the series:
Code: Select all
private
{ Private declarations }
function mySerieGetPointerStyle(Sender:TChartSeries;
ValueIndex:Integer): TSeriesPointerStyle;
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
//...
mySerie.OnGetPointerStyle:=mySerieGetPointerStyle;
//...
end;
Re: How to give points different style
Posted: Wed May 18, 2016 8:00 am
by 16576425
Hi
Thanks. It worked. But I get an extra point at (0,0). Do you know why I get that and how to avoid it?
I believe that I saw a similar report in another post, but cannot find it now.
BR
Amin
Re: How to give points different style
Posted: Wed May 18, 2016 4:06 pm
by 16576425
Hi
Please ignore my last post. I found the problem which was that I have indexed the color vector from 1 to N instead of 0 to (N-1).
BR
Amin
Re: How to give points different style
Posted: Thu May 19, 2016 7:11 am
by yeray
Hello,
Good! Don't hesitate to let us know if you find any problem with the library.