Hierarchy Properties Methods Events
TDBChart derives from TChart / TCustomChart and inherits all TChart functionality.
When a Chart Series is connected to a TDBChart component, TDBChart looks in the Series DataSource property.
If DataSource is a TTable, TQuery, TClientDataset or any valid DataSet component, TDBChart will automatically retrieve its records preserving all Filters and Ranges. You can also filter which records would be inserted by using the Series OnBeforeAdd event.
TDBChart also accepts Chart Series which are connected to another Chart Series and also Chart Series whose points are being manually added by coding.
The main difference between TChart and TDBChart is that the last one NEEDS the VCL DB.pas unit (the database core unit), while TChart component does not.
The above would be useful in case your application does not need Tables, Querys or any standard Delphi/C++ Builder database components.
Changing from a TChart to a TDBChart or vice versa can be done both at design and runtime by changing the Series ParentChart
and the Series Values ValueSource properties.
Notes on use of TDBChart
OnGetText TField support
Now DBChart uses (if assigned) the default standard Delphi's TField "OnGetText" event, for Series Labels:
procedure TForm1.Table1NAMEGetText(Sender: TField; var Text: String;
Refer to Delphi's Help of TField.OnGetText for more details.
Null field values
DBChart detects NULL field values properly, and adds null points to the Series using the Series.AddNull method and / or AddNullXY methods.
You can connect a Series1 to a Delphi's TDataSource component.
This allows to plot single-record multiple-field values into a single Series without any programming.
The "trick" is to set the Field names you want to plot together separated with ";"
Series1.DataSource := DataSource1;
Series1.YValues.ValueSource := 'Field1;Field2;Field3'
The current DataSource record will be used to plot the specified field values.
The DBChart does not move the current record position, and, when the DataSource changes the current record ( by for example using a TDBNavigator ), it refreshes the chart again with the new record values.
Updates to the underlying dataset force a refresh, so the DBChart retrieves the current record again.
The "DataSource" tab at the Chart Editor dialog includes "single-record" TDataSource component and fields selection as an option:
Like in the TDataSet normal datasource dialogs, TDataSource components can be located at TDataModules or any "used" Form.