Search code examples
delphitstringgrid

plot stringgrid values on Tchart


I'm trying to plot a graph with some values on my Stringgrid. it has 140x140 rowxCol, numbers only. The Tchart should display on the X-axis the cell coordinates, in the y-axis the values.

I'm using this code:

procedure TForm2.Button2Click(Sender: TObject);
var 
  Count: Integer;
begin
  with StringGrid1 do
  begin
    for Count := 0 to RowCount-1 do
    begin
      Chart1.Series[0].AddXY(StrToFloat(Cells[0, Count]), 
                             StrToFloat(Cells[1, Count]), '', clTeeColor);
    end;
  end;
end;

But I keep getting this error: '' is not a floating point value.


Solution

  • You're converting an empty string to a floating point value, what is naturally impossible. My guess is that you're passing wrong coordinates to the Cells property. Note that they're both 0 based and that they include also the fixed portion of the string grid. Here's the Cells coordinates printout:

    enter image description here