1

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?

Code:

var
   i:Integer;
   Bar:TBarSeries;
begin
   ADataSet.Close;
   ADataSet.LoadFromDataSet(mtbl);
   ADataSet.Active := true;
   ADataSet.First;
   ASource.DataSet := ADataSet;

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

   for i := 0 to AChart.SeriesCount - 1 do
   begin
      AChart.Series[i].CheckDataSource;
   end;

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.

2
  • 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. Commented Feb 10, 2009 at 3:53
  • I understand, I used TeeChart to emphasis this is Steema's component, not Delphi's default one. Commented Feb 10, 2009 at 4:40

2 Answers 2

3

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);  
var   
    Bar : TBarSeries;  
begin  
    ADODataSet1.Close;  
    ADODataSet1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;...';  
    Bar := TBarSeries.Create(DBChart1);  
    DBChart1.AddSeries(Bar);  
    Bar.ParentChart := DBChart1;  
    Bar.DataSource := ADODataSet1;  
    Bar.XLabelsSource := 'ID';  
    Bar.YValues.ValueSource := 'Height';  
    ADODataSet1.Active := true;  
end;

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this worked. I got rid of the DataSource, did this instead and it worked: Bar.DataSource := ADataSet
Judging from TeeChart sources, assigning TDataSet TDataSource results in internal call to CheckNewDataSource(const ADataSet:TDataSet; SingleRow:Boolean), where for TDataSet-derived classes the SingleRow parameter is False, and fo TDataSource-s, do not ask me why, it is True.
0

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).

2 Comments

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.
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?\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.