Integrating Basic Charts into Delphi Applications

mla apa chicago
Your Citation
Gajic, Zarko. "Integrating Basic Charts into Delphi Applications." ThoughtCo, Aug. 22, 2016, Gajic, Zarko. (2016, August 22). Integrating Basic Charts into Delphi Applications. Retrieved from Gajic, Zarko. "Integrating Basic Charts into Delphi Applications." ThoughtCo. (accessed October 23, 2017).
Businessman walking in front of graphs on screen
Monty Rakusen/Cultura/Getty Images

In most modern database applications some kind of graphical data representation is preferable or even required. For such purposes Delphi includes several data aware components: DBImage, DBChart, DecisionChart, etc. The DBImage is an extension to an Image component that displays a picture inside a BLOB field. Chapter 3 of this database course discussed displaying images (BMP, JPEG, etc.) inside an Access database with ADO and Delphi.

The DBChart is a data aware graphic version of the TChart component.

Our goal in this chapter is to introduce the TDBChart by showing you how to integrate some basic charts into your Delphi ADO based application.


The DBChart component is a powerful tool for creating database charts and graphs. It is not only powerful, but also complex. We wont be exploring all of its properties and methods, so you'll have to experiment with it to discover all that it is capable of and how it can best suite your needs. By using the DBChart with the TeeChart charting engine you can quickly make graphs directly for the data in datasets without requiring any code. TDBChart connects to any Delphi DataSource. ADO recordsets are natively supported. No additional code is required - or just a little as you'll see. The Chart editor will guide you through the steps to connect to your data - you don't even need to go to the Object Inspector.

Runtime TeeChart libraries are included as part of Delphi Professional and Enterprise versions. TChart is also integrated with QuickReport with a custom TChart component on the QuickReport palette. Delphi Enterprise includes a DecisionChart control in the Decision Cube page of the Component palette.

Let's Chart! Prepare

Our task will be to create a simple Delphi form with a chart filled with values from a database query. To follow along, create a Delphi form as follows:

1. Start a a new Delphi Application - one blank form is created by default. 

2. Place the next set of components on the form: ADOConnection, ADOQuery, DataSource, DBGrid and a DBChart. 

3. Use the Object Inspector to connect ADOQuery with ADOConnection, DBGrid with DataSource with ADOQuery. 

4. Set up a link with our demo database (aboutdelphi.mdb) by using the ConnectionString of the ADOConnection component. 

5. Select the ADOQuery component and assign the next string to the SQL property:

SELECT TOP 5 customer.Company,
SUM(orders.itemstotal) AS SumItems,
COUNT(orders.orderno) AS NumOrders
FROM customer, orders
WHERE customer.custno = orders.custno
GROUP BY customer.Company
ORDER BY SUM(orders.itemstotal) DESC

This query uses two tables: orders and customer. Both tables were imported from the (BDE/Paradox) DBDemos database to our demo (MS Access) database. This query results in a recordset with only 5 records. The first field is the Company name, the second (SumItems) is a sum of all the orders made by the company and the third field (NumOrders) represents the number of orders that were made by the company.

Note that those two tables are linked in a master-detail relationship. 

6. Create a persistent list of database fields. (To invoke the Fields Editor double click the ADOQuery component. By default, the list of fields is empty. Click Add to open a dialog box listing the fields retrieved by the query (Company, NumOrders, SumItems). By default, all fields are selected. Select OK.) Even though you don't need a persistent set of fields to work with a DBChart component - we'll create it now. The reasons will be explained later. 

7. Set ADOQuery.Active to True in the Object Inspector to see the resulting set at design time.