Solved

How do I define a series for TChart without using the object inspector?

Posted on 2002-06-27
2
862 Views
Last Modified: 2010-04-04
I have 56 charts I want to show on a single form.  Rather than define each individually I set the charts up using an array of Tchart and defined as shown in the code below.  

var
  TestProgressForm: TTestProgressForm;
   Charts : array[1..MAX_WFR_COL,1..MAX_WFR_ROW] of Tchart;

Procedure TTestProgressForm.AssignChartProperties;
var col,row : integer;
begin
    for row := 1 to MAX_WFR_ROW do begin
    for col := 1 to MAX_WFR_COL do begin
      Charts[col,row] := Tchart.Create(TestProgressForm);
      Charts[col,row].Parent := TestProgressForm;
      charts[col,row].Enabled := TRUE;
      charts[col,row].BackWall.Color :=clRed;
      charts[col,row].Width := 80;
      charts[col,row].Height := 80;
      charts[col,row].MarginBottom := 0;
      charts[col,row].MarginLeft := 0;
      charts[col,row].MarginRight := 0;
      charts[col,row].MarginTop := 0;
      charts[col,row].Visible := True;
      charts[col,row].BackColor := clWhite;
      Charts[col,row].BottomAxis.Visible := FALSE;
      charts[col,row].LeftAxis.Visible := FALSE;
      charts[col,row].Legend.Frame.Visible := FALSE;
      charts[col,row].RightAxis.Visible := FALSE;
      charts[col,row].TopAxis.Visible := FALSE;
      charts[col,row].Title.Frame.Visible := FALSE;
      charts[col,row].View3D := FALSE;
      charts[col,row].Top := 525 - (row-1)*(charts[col,row].Height + 5);
      charts[col,row].Left := 55 + (col-1)*(charts[col,row].Width + 5);
    end;
  end;
end;

Defining the charts seems to work fine.  What I am having problems with is setting up the series associated with the chart.  I want to set up a barchart with 9 bars.  When I tried it using the object inspector the following code seemed to work fine:

type
  TTestProgressForm = class(TForm)
    ChartC4R7: TChart;
    BarSeries5: TBarSeries;
...

  (ChartC4R7.Series[0]as TBarSeries).CustomBarWidth := 10;
  (ChartC4R7.Series[0]as TBarSeries).AddXY(1,100,'',clGreen);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(2,100,'',clRed);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(3,100,'',clRed);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(4,100,'',clGreen);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(5,100,'',clGreen);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(6,100,'',clRed);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(7,100,'',clSkyBlue);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(8,100,'',clBlue);
  (ChartC4R7.Series[0]as TBarSeries).AddXY(9,100,'',clGreen);

When I try to do the same code using Charts[col,row] instead of ChartC4R7 I get the following Debugger Exception Notification:

Project WaferProber.exe raised exception class ElistError with message 'List index out of bounds(0)'....

I know I must be missing a step but I don't know what it is.

Thanks,
P





0
Comment
Question by:PattiGaultney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7114366
I guess you should also create your TBarSeries.
"List index out of bounds (0)" probably means you're trying to access Series[0] while there is no series component.
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 100 total points
ID: 7114409
I've read the title of your question and it seems you're already aware of the cause of the error; and you're actually asking how to set up the bar series.
Here is a quick code snippet:

procedure TForm1.Button1Click(Sender: TObject);
var
  Chart: TChart;
  BarSeries: TBarSeries;
begin
  Chart := TChart.Create(Self);
  try
    Chart.Parent := Self;
    Chart.Left := 8;
    Chart.Top := 8;
    BarSeries := TBarSeries.Create(Self);
    try
      Chart.AddSeries(BarSeries);
      // your code
      with Chart.Series[0] as TBarSeries do
      begin
        CustomBarWidth := 10;
        AddXY(1,100,'',clGreen);
        AddXY(2,100,'',clRed);
        AddXY(3,100,'',clRed);
        AddXY(4,100,'',clGreen);
        AddXY(5,100,'',clGreen);
        AddXY(6,100,'',clRed);
        AddXY(7,100,'',clSkyBlue);
        AddXY(8,100,'',clBlue);
        AddXY(9,100,'',clGreen);
      end;
    except
      BarSeries.Free;
      raise;
    end;
  except
    Chart.Free;
    raise;
  end;
end;

HTH
TOndrej
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 21 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question