![]() |
How to Create Data-Aware Charts
The only difference between TChart and TDBChart is TChart does not need the database units.
However, points must be manually added by programming.
TDBChart, in contrast, accepts Series connected to database components (like TTable, TQuery or TClientDataset).
TDBChart will retrieve database records and will automatically add the points.
Add a data table to your form
1) Place a TTable component and assign to it an existing Table.
It is not necessary to make the table Active at this stage.
Steps to create a simple data-aware chart
(You can do all steps without programming, using the Chart editor)
2) Place a TDBChart in your form.
3) Right mouse key on the Chart to call up the TeeChart menu then select the Chart editor menu option or Double-click on the chart to go straight to the Chart editor.
4) In the Chart editor add a Series to the Chart by clicking on the Add button. This will call the TeeChart Gallery.Select a series type and click OK.
5) Back in the Chart editor select the Series page with the tab selector (or double-click on your series in the editor series list)
6) On the series page select your new series in the Series Combobox (If you only have one series in the chart it will automatically be displayed in the combobox). Click on the datasource tab to add the new datasource.
7) Select Dataset from the dropdown combobox to define the DataSource property.
Now you can set the series data sources:
8) Set the Dataset field to Table1.
9) Now you need to set Table Fields that will be used to draw your data series: Set the Labels field to the desired table Field. (for example: Table1.CityName) Set the Y values to the desired Vertical Table Field. (for example: Table1.Population). The fields available in this tab page of the Chart editor will depend on the series you are adding. For example a LineSeries will a permit the use of X and Y co-ordinates and an optional Label field, a Pie-series only uses the label field and one set of values. See the Series unit for more information.
Activate your data
10) Now set Active to True (or Open) the Table. Opening or closing the Table will force TDBChart to retrieve the records again, thus allowing refresh.
Color in fields:
It is also possible to have the point colors in a Table or Query field. The field must be a Numeric field containing RGB (Red,Green,Blue) values. Assign the LineSeries1.ColorSource property to this field.
Colors are expressed as numbers, please refer to the Delphi and Windows help to know more about RGB colors. (TColorType)