Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

10 Experts available now in Live!

Get 1:1 Help Now