Another ColorGrid question

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Another ColorGrid question

Post by RSpence » Mon Mar 14, 2005 11:50 pm

Is it possible to change the pen used to draw the border around specific squares in a colorGrid? I have a grid with 85 columns and 60 rows, filled with colors. Subsequently, I need to "highlight" certain cells - and I think the best way to do this is to change the color of the cell's border? Possible?

Regards,

Rick

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Mar 15, 2005 7:46 am

Hi, Rick.

Not individual cell border. But you can get the same result by manually drawing rectangle over the selected cell in tChart OnAfterDraw event.
Marjan Slatinek,
http://www.steema.com

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Tue Mar 15, 2005 8:32 pm

OK that's clear - so let's say I want to draw a rectangle around cell [3, 4]. How do I find the coordinates?

Thanks,

Rick

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Wed Mar 16, 2005 7:42 am

Hi, Rick.

You could try using something along these lines:

Code: Select all

function HighlightRect(Series: TCustom3DGridSeries; XInd, ZInd: Integer): TRect;
begin
  With Series do
  begin
    Result.Left := CalcXPos(XInd);
    Result.Right := CalcXPos(XInd+1);
    Result.Top := GetVertAxis.CalcPosValue(ZValues.Value[GridIndex[XInd+1,ZInd+2]]);
    Result.Bottom := GetVertAxis.CalcPosValue(ZValues.Value[GridIndex[XInd+1,ZInd+1]]);
  end;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var R: TRect;
begin
  r := HighlightRect(Series1,3,2);
  With Chart1.Canvas, Chart1 do
  begin
    Brush.Style := bsClear;
    Pen.Color := clRed;
    Pen.Width := 2;
    Inc(R.Left,Pen.Width div 2);
    Inc(R.Top,Pen.Width div 2);
    ClipRectangle(ChartRect);
    Rectangle(R);
    UnclipRectangle;
  end;
end;
The example does not actually check if XInd and ZInd are inside valid values .. you can add this and extend the code.
Marjan Slatinek,
http://www.steema.com

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Wed Mar 16, 2005 6:33 pm

Thanks for this. I'll play with it and see what I get.

Regards,

Rick

RSpence
Newbie
Newbie
Posts: 33
Joined: Fri Apr 02, 2004 5:00 am
Location: UK / Florida
Contact:

Post by RSpence » Sat Mar 19, 2005 12:01 am

Hi Marjan,

I checked out this code. It almost works with two issues:

1. The calculation of the right coordinate in the HightRect function is returning the same value as left. It seems to need scaling somehow. In the exampe I have if I add 1 thru 3 to XIND it continues to return the same as the left coordinate. If I add 4 to it it returns the correct value. In this case 4 is the number of ticks between values on the X axis.

2. If I change the brush style to bsSolid, and set a color, as in:

brush.style := bsSolid;
brush.Color := clGreen;

I would expect a solid color of green inside the rectangle and a red border. It remains white.

Thnks,

Rick

Post Reply