Page 1 of 1
TColorGrid read data value & transpancy question
Posted: Wed Mar 22, 2006 9:42 pm
by 9234539
Hi,
I have a question here, how do I get the value from TColorGridSeries, ex. for a regular grid 3x3, I add data
[ 3 4 4
4 5 6
4 6 8], but how to get the data say with index (2,1) back from series.
One more question, does latest version support set one color as transparent color for TColorGridSeries and plot two colorgrid at the same time?
Thanks
Best Regards
Fang
Posted: Thu Mar 23, 2006 8:59 am
by narcis
Hi Fang,
I have a question here, how do I get the value from TColorGridSeries, ex. for a regular grid 3x3, I add data
[ 3 4 4
4 5 6
4 6 8], but how to get the data say with index (2,1) back from series.
You can use Clicked method doing something like this:
Code: Select all
procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i: Integer;
begin
i:=Series1.Clicked(X,Y);
Chart1.Title.Text[0]:=FloatToStr(Series1.YValue[i]);
end;
Or you can use GetColumn and GetRow methods implemented in the example below.
Code: Select all
var
Form1: TForm1;
X0,Y0,X1,Y1,XIndex,YIndex: Integer;
DrawRect: Boolean;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(10);
Chart1.Zoom.Allow:=false;
end;
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Memo1.Clear;
X0:=X;
Y0:=Y;
XIndex:=Series1.Clicked(X0,Y0);
DrawRect := true;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if DrawRect then
begin
X1:=X;
Y1:=Y;
Chart1.Repaint;
end;
end;
procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DrawRect := false;
YIndex:=Series1.Clicked(X1,Y1);
GetRectIndexes;
Chart1.Repaint;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
With Chart1.Canvas do
begin
Pen.Color:=clWhite;
Pen.Width:=2;
Brush.Style:=bsClear;
Rectangle(X0,Y0,X1,Y1);
end;
end;
procedure TForm1.GetRectIndexes;
var
Col0,Row0,Col1,Row1,x,z: Integer;
begin
Col0:=GetColumn(XIndex);
Row0:=GetRow(XIndex);
Col1:=GetColumn(YIndex);
Row1:=GetRow(YIndex);
for x:=Min(Col0,Col1) to Max(Col0,Col1) do
for z:=Min(Row0,Row1) to Max(Row0,Row1) do
Memo1.Lines.Add(FloatToStr(Series1.YValues[(x*10)+z]));
end;
function TForm1.GetColumn(ValueIndex: Integer): Integer;
begin
result:=ValueIndex div Series1.NumXValues;
end;
function TForm1.GetRow(ValueIndex: Integer): Integer;
begin
result:=ValueIndex mod Series1.NumZValues;
end;
One more question, does latest version support set one color as transparent color for TColorGridSeries and plot two colorgrid at the same time?
If you want to set a TColorGridSeries cell being transparent you can set its color to
clNone. And yes, two ColorGrids can be drawn at the same time, for example:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
For i:=0 to 5 do
begin
Series1.AddXYZ(i,random,i);
Series2.AddXYZ(i+6,random,i);
end;
Chart1.View3D:=false;
end;
Posted: Thu Mar 23, 2006 12:29 pm
by 9234539
thanks, Narcis, I'll try that.
for the transparancy, I mean, for one color of the series, not all the color, but anyway I'll try it before I raise it again.
Posted: Thu Mar 23, 2006 2:46 pm
by narcis
Hi Fang,
Yes, that's what I meant, you can add values to the series doing something like:
Posted: Thu Mar 23, 2006 6:54 pm
by 9234539
I couldn't make it work. Here's the newbie question,
I got X,Y from OnChartMouseMove, is this same as the X,Y in OnSeriesClick ?
if not, how do I quickly convert to the OnSeriesClick version ? thanks.
Fang
Posted: Thu Mar 23, 2006 6:55 pm
by 9234539
sorry, I should read your post again. my bad