2. Chart1.SeriesGroups.Items[0].Add(Series_0); does not add the series. I have to invoke Chart1.AddSeries(Series_0);
to get series to show. Why doesn't Chart1.SeriesGroups.Items[0].Add(Series_0); add the series?
I want two groups with 3 items in each. See screen shot below. Using TeeChart is not intuitively obvious. I used it years ago w/Delphi 5 and do not remember complications and misunderstanding of properties/methods.
As written, code produces no output displayed in chart.
Thanks
Robert
Code: Select all
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Chart, TeEngine, Series;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Chart1: TChart;
Series_0, Series_1 : THorizBarSeries;
sTest : String;
begin
try
Chart1 := TChart.Create(self);
Chart1.Parent := self;
Chart1.Top := 0;
Chart1.Left := 0;
Chart1.Height := 450;
Chart1.Width := 800;
Chart1.View3D := False;
Chart1.View3DWalls := False;
Chart1.RemoveAllSeries;
Chart1.Pages.MaxPointsPerPage := 10;
(Chart1.SeriesGroups.Add as TSeriesGroup).Name:='SeriesGgroup_0';
Series_0 := THorizBarSeries.Create(Self);
// Chart1.AddSeries(Series_0);
sTest := Chart1.SeriesGroups.Items[0].Name;
Chart1.SeriesGroups.Items[0].Add(Series_0);
// Chart1.AddSeries(Series_0);
Series_0.CustomBarHeight := 30;
Series_0.OffsetPercent := 80;
Series_0.BarWidthPercent := 200;
Series_0.Marks.Style := smsValue;
Series_0.Add(123, 'S0_1', clRed);
Series_0.Add(456, 'S0_2', clBlue);
Series_0.Add(789, 'S0_3', clGreen);
(Chart1.SeriesGroups.Add as TSeriesGroup).Name:='SeriesGgroup_1';
Series_1 := THorizBarSeries.Create(Self);
// Chart1.AddSeries(Series_1);
sTest := Chart1.SeriesGroups.Items[1].Name;
Chart1.SeriesGroups.Items[1].Add(Series_1);
// Chart1.AddSeries(Series_1);
Series_1.CustomBarHeight := 30;
Series_1.OffsetPercent := 80;
Series_1.BarWidthPercent := 200;
Series_1.Marks.Style := smsValue;
Series_1.Add(456, 'S1_1', clRed);
Series_1.Add(123, 'S1_2', clBlue);
Series_1.Add(987, 'S1_3', clGreen);
finally
//Chart1.Free;
end;
end;
end.