Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TeeChart - Populate More Than 1 Series at a time? 1

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
Hi, im filling a teechart which contains 4 series based on values from a listview's subitems[x] property.

However it only seems to work with one of the series, it ignores the rest (will only ever populate one series at a time).

The series are:

LeftBicepSeries
RightBicepSeries
LeftForearmSeries
RightForearmSeries

The chart is to show if any training i do makes how much of a differece.

Code:
procedure TfrmMain.UpdateLeftBicepSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  try
    aStringList:= TStringList.Create;

    with LeftBicepSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the weight training table and:
      -> get the value entered in all muscle part boxes
      -> add to the weight training chart the number of months based on if each muscle part has a value}
      for i:= 0 to lvwWeightTrainingTable.Items.Count do
      begin
        if lvwWeightTrainingTable.Items[i].SubItems.Count > 5 then
        begin
          if lvwWeightTrainingTable.Items[i].SubItems[5] <> '' then
          begin
            {add muscle part values to stringlist}
            aStringList.Add(lvwWeightTrainingTable.Items[i].SubItems[5]);

            {add to the chart, we can now count actual months via aStringList.Count}
            Add(StrToFloat(lvwWeightTrainingTable.Items[i].SubItems[5]), IntToStr(aStringList.Count), clNone);
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;

procedure TfrmMain.UpdateRightBicepSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  try
    aStringList:= TStringList.Create;

    with LeftBicepSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the weight training table and:
      -> get the value entered in all muscle part boxes
      -> add to the weight training chart the number of months based on if each muscle part has a value}
      for i:= 0 to lvwWeightTrainingTable.Items.Count do
      begin
        if lvwWeightTrainingTable.Items[i].SubItems.Count > 6 then
        begin
          if lvwWeightTrainingTable.Items[i].SubItems[6] <> '' then
          begin
            {add muscle part values to stringlist}
            aStringList.Add(lvwWeightTrainingTable.Items[i].SubItems[6]);

            {add to the chart, we can now count actual months via aStringList.Count}
            Add(StrToFloat(lvwWeightTrainingTable.Items[i].SubItems[6]), IntToStr(aStringList.Count), clNone);
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;

procedure TfrmMain.UpdateLeftForearmSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  try
    aStringList:= TStringList.Create;

    with LeftBicepSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the weight training table and:
      -> get the value entered in all muscle part boxes
      -> add to the weight training chart the number of months based on if each muscle part has a value}
      for i:= 0 to lvwWeightTrainingTable.Items.Count do
      begin
        if lvwWeightTrainingTable.Items[i].SubItems.Count > 7 then
        begin
          if lvwWeightTrainingTable.Items[i].SubItems[7] <> '' then
          begin
            {add muscle part values to stringlist}
            aStringList.Add(lvwWeightTrainingTable.Items[i].SubItems[7]);

            {add to the chart, we can now count actual months via aStringList.Count}
            Add(StrToFloat(lvwWeightTrainingTable.Items[i].SubItems[7]), IntToStr(aStringList.Count), clNone);
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;

procedure TfrmMain.UpdateRightForearmSeries;
var
  i: Integer;
  aStringList: TStringList;
begin
  try
    aStringList:= TStringList.Create;

    with LeftBicepSeries do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the weight training table and:
      -> get the value entered in all muscle part boxes
      -> add to the weight training chart the number of months based on if each muscle part has a value}
      for i:= 0 to lvwWeightTrainingTable.Items.Count do
      begin
        if lvwWeightTrainingTable.Items[i].SubItems.Count > 8 then
        begin
          if lvwWeightTrainingTable.Items[i].SubItems[8] <> '' then
          begin
            {add muscle part values to stringlist}
            aStringList.Add(lvwWeightTrainingTable.Items[i].SubItems[8]);

            {add to the chart, we can now count actual months via aStringList.Count}
            Add(StrToFloat(lvwWeightTrainingTable.Items[i].SubItems[8]), IntToStr(aStringList.Count), clNone);
          end;
        end;
      end;
    end;
  finally
    aStringList.Free;
  end;
end;

now if i call it like so it only updates the first series (if i comment LeftBicepSeries out it only shows RightBicepSeries etc)

Code:
UpdateLeftBicepSeries;
UpdateRightBicepSeries; {not showing in chart}
UpdateLeftForearmSeries; {not showing in chart}
UpdateRightForearmSeries; {not showing in chart}

So i basically want to know why i cant update the teechart and all series at the same time??

Thanks!
 
forgot to add im using the FastLine type series
 
There's several things I would change, the 1st is a must:
for all your loops
Code:
for i:= 0 to lvwWeightTrainingTable.Items.Count do
should be:
Code:
for i:= 0 to lvwWeightTrainingTable.Items.Count [red]-1[/red] do
The 2nd is to make this a common function, like this:
Code:
function TfrmMain.UpdateSeries(aTable: TTable; MyIndex: integer): boolean;
var
  i: Integer;
  aStringList: TStringList;
begin
  result:= true;
  try
    aStringList:= TStringList.Create;

    with aTable do
    begin
      Clear; //clear previous entries otherwise it will keep adding

      {loop through each entry in the weight training table and:
      -> get the value entered in all muscle part boxes
      -> add to the weight training chart the number of months based on if each muscle part has a value}
      try
        for i:= 0 to aTable.Items.Count -1 do
        begin
          if aTable.Items[i].SubItems.Count > MyIndex then
          begin
            if aTable.Items[i].SubItems[MyIndex] <> '' then
            begin
              {add muscle part values to stringlist}
              aStringList.Add(aTable.Items[i].SubItems[MyIndex]);

              {add to the chart, we can now count actual months via aStringList.Count}
              Add(StrToFloat(aTable.Items[i].SubItems[MyIndex]), IntToStr(aStringList.Count [red]-1[/red]), clNone);
            end;
          end;
        end;
      except
        result:= false  
      end;
    end;
  finally
    aStringList.Free;
  end;
end;
Now call them with:
Code:
  if UpdateSeries(LeftBicepSeries, 5) then
    if UpdateSeries(RightBicepSeries, 6) then
      if UpdateSeries(LeftForearmSeries, 7) then
        if UpdateSeries(RightForearmSeries, 8) then
          //sucess message
        else //error message
      else //error message
    else //error message
  else //error message
Hope that makes sense, I don't have delphi on this laptop so was done freehand.

Roo
Delphi Rules!
 
one more thing:

when you create things, don't do it in the try/finally block.

if the create part somehow fails (like out of memory) the destroy part is automatically called.
This means if you put the Create part inside the try/finally block, your object will get freed twice in case of create problems (resulting in AV offcourse).

so general rule:

Code:
obj.create
try
 //  code
finally
 obj.free (or better : FreeAndNil(Obj)
end;

Daddy out...


-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
thanks, i actually got the chart to update all series by using the proper coding style roo suggested - i was freeing the stringlist and trying to use it once it had finished the subroutine.

cheers all
 
@simmo09:

Don't forget to click "Thank (handle) for this valuable post" because it looks like they both helped you quite a bit. I realized myself that I hadn't done this in a while, so I queried all my posts and clicked to thank the expert who helped me. whosrdaddy and roo0047 are both big helps every time.

GIS Programmer
City of Orem, UT
 
@simmo09: Thanks for the *
@MagicFrisbee: thank you & for the vote of confidence.
daddy is the man.


Roo
Delphi Rules!
 
no problem, its pretty hard to get delphi help, im registered at dev forums too, but the help their is not so great.

thanks again everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top