Sign up ×

Using Delphi Steema TeeChart component, if I link a BarSeries to a dataset using the user interface, it shows up fine, but if I do it using code (which I need to), it's only showing one bar, even when I have several records in the database. What am I doing wrong?


   ADataSet.Active := true;
   ASource.DataSet := ADataSet;

   Bar := TBarSeries.Create(AChart);
   Bar.ParentChart := AChart;
   Bar.DataSource := ASource;
   Bar.XLabelsSource := 'Date';
   Bar.YValues.ValueSource := 'Load';

   for i := 0 to AChart.SeriesCount - 1 do

ADataSet is a DevExpress MemData (TdxMemData). When I run the program, the X axis is only showing one bar, the first record in the dataset, even though I have 4 records in the dataset.

share|improve this question
The name of the component is "tchart", so you might want to edit your title and text. There are a couple of other StackOverflow questions tagged "tchart", so this will help in searching for similar. –  Argalatyr Feb 10 '09 at 3:53
I understand, I used TeeChart to emphasis this is Steema's component, not Delphi's default one. –  Robo Feb 10 '09 at 4:40

2 Answers 2

up vote 3 down vote accepted

This code works for me (using an Access database with fields ID and Height, I dropped a TDBChart, TADODataSet, and a TButton on a form):

procedure TForm1.Button1Click(Sender: TObject);  
    Bar : TBarSeries;  
    ADODataSet1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;...';  
    Bar := TBarSeries.Create(DBChart1);  
    Bar.ParentChart := DBChart1;  
    Bar.DataSource := ADODataSet1;  
    Bar.XLabelsSource := 'ID';  
    Bar.YValues.ValueSource := 'Height';  
    ADODataSet1.Active := true;  

Note that the Datasource should be a TTable, TQuery, or TDataSet (not a TDataSource - go figure!).

Hope this helps.

share|improve this answer
Thanks, this worked. I got rid of the DataSource, did this instead and it worked: Bar.DataSource := ADataSet –  Robo Feb 10 '09 at 21:53
Great! I'm glad that helped. –  Argalatyr Feb 11 '09 at 0:27

TChart refreshes the query each time you set

ADataSet.Active := true;

so, move this command to the end of your block (e.g. after you've set up the series properties).

share|improve this answer
Thanks, but this didn't help. I moved LoadFromDataSet and Active := true to below the part where TBarSeries gets setup, and it still showed only one record. Since it showed one record, it must know the dataset is active and has records inside, not sure why it's not displaying all of them. –  Robo Feb 10 '09 at 4:44
Have you tried temporarily switching to a generic delphi dataset (say just a tadodataset pointed to an Excel spreadsheet, something simple like that) to separate the vendors (dbx and steema) for this issue?\ –  Argalatyr Feb 10 '09 at 5:29

Your Answer


