Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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