Page 1 of 1

problems with chart

Posted: Thu Sep 10, 2015 7:53 pm
by 15670445
Hi,

I'm having problems with the following code. It gives me the error "...EListError with message 'List index out of bounds (-1)'


I'm using TeeChart Pro 2013.09.131110 32 Bit VCL

1) it seems that disabling chart1.leftaxis.setminmax solves the problems but if I really need to setminmax...
2) If you disable chart1.leftaxis.setminmax, the problems disapperas but reappears when trying to zoom

Code: Select all


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, TeeGDIPlus, ExtCtrls, TeeProcs, TeEngine, Chart, Series;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Chart1: TChart;
    Series1: THorizBarSeries;
    Procedure MakeLegendChart2;
    Procedure InitializeChart(const XChart:TChart);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.FormShow(Sender: TObject);
begin

InitializeChart(Chart1);
MakeLegendChart2;


Chart1.leftaxis.Title.Caption := 'Production Order Number';
Chart1.BottomAxis.Title.Caption := 'Number of Profiles';
Chart1.Title.Clear;
Chart1.Title.Text.Add('Production Order Number vs. Number of Profiles');
Chart1.Legend.Alignment := laBottom;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'Number of Profiles to be Produced';
    ShowInLegend := False;
    shadow.Visible := false;
    XValues.DateTime := false;
    Marks.Style := smsValue;
    Marks.Shadow.Visible := false;
    brush.Style := bsSolid;
    StackGroup := 2;
    Marks.Clip := true;
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'Number of Profiles Already Produced';
    ShowInLegend := false;
    shadow.Visible := false;
    XValues.DateTime := false;
    Marks.Style := smsValue;
    Marks.Shadow.Visible := false;
    brush.Style := bsDiagCross;
    seriescolor := clBlack;
    StackGroup := 1;
    Marks.Clip := true;
  end;

//=====================================

with Chart1[Chart1.SeriesCount -2] as THorizBarSeries do
  addxy(420,0,'P04567',clred);

with Chart1[Chart1.SeriesCount -2] as THorizBarSeries do
  addxy(210,1,'P04566',cllime);

chart1.LeftAxis.SetMinMax(-1,2);

end;

Procedure TForm1.InitializeChart(const XChart:TChart);
begin

with XChart do
begin
Color := clwhite;
Gradient.Visible := false;
BackWall.Color := clWhite;
BackWall.Gradient.Visible := false;
View3D := false;
BevelOuter := BvNone;

FreeAllSeries();
RemoveAllSeries;
Title.Text.Clear;
Legend.Shadow.Visible := false;
legend.Font.Size := 14;
legend.Symbol.Width := 50;
legend.Symbol.Squared := true;
end;
end;



Procedure TForm1.MakeLegendChart2;
begin

Chart1.Legend.Visible := true;
Chart1.Legend.Alignment := laBottom;
Chart1.Legend.LegendStyle := lsSeries;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040059';
    ShowInLegend := true;
    seriescolor := clred;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clred);
  end;


with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040170';
    ShowInLegend := true;
    seriescolor := clAQUA;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clAQUA);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040190';
    ShowInLegend := true;
    seriescolor := clLIME;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clLIME);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040198';
    ShowInLegend := true;
    seriescolor := clFuchsia;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clFuchsia);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040211';
    ShowInLegend := true;
    seriescolor := clGray;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clGray);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040193';
    ShowInLegend := true;
    seriescolor := clBlue;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clBlue);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'ItemNumber 040182';
    ShowInLegend := true;
    seriescolor := clPurple;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clPurple);
  end;

with Chart1.AddSeries(THorizBarSeries.Create(self)) as THorizBarSeries do
  begin
    ParentChart := Chart1;
    Title := 'Amount Produced';
    ShowInLegend := true;
    brush.Style := bsDiagCross;
    seriescolor := clBlack;
    StackGroup := 0;
    MultiBar := mbStacked;

    with Chart1[Chart1.SeriesCount-1] as THorizBarSeries do
        addxy(1,-2,'',clBlack);
  end;

end;

end.


Re: problems with chart

Posted: Mon Sep 14, 2015 10:48 am
by yeray
Hello,

I could reproduce the error with your code and TeeChart v2013.09 and v2014.10 but not with v2014.11 and neither with the actual version v2015.16.
So I'd suggest you to upgrade to the latest version.