Solved

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

Posted on 2002-06-27
2
800 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now