The OnDrawCell event is made for any kind of custom painting:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
const
xmax = 10;
var
x: Integer;
w, h: Integer;
begin
if ACol = 2 then begin
if StringGrid1.Cells[ACol-1, ARow] = '' then
exit;
x := StrToInt(StringGrid1.Cells[ACol-1, ARow]);
StringGrid1.Canvas.Brush.Style := bsSolid;
StringGrid1.Canvas.Brush.Color := clBlue;
w := ARect.Right - ARect.Left;
h := (ARect.Bottom - ARect.Top) div 2;
StringGrid1.Canvas.FillRect(
ARect.Left,
(ARect.Top + ARect.Bottom - h) div 2,
ARect.Left + round(x / xmax * w),
(ARect.Top + ARect.Bottom + h) div 2
);
end;
end;
In this example the first column of the grid contains some integers between 0 and 10. Then this code paints a bar in column 2 according to the value in column. The height of the bar is half a cell height (line 16).
Just assign this code to the OnDrawCell event of the grid, no other changes required.
[EDIT]
Ah, I see after posting that you have a DBGrid, not a StringGrid. Here you get the value to be plotted from the database field in that particular field, but the idea is the same.