Diagrams FastReport allows to insert diagrams into the report. For this purpose, the "TfrxChartObject" object from the FastReport component palette is used. The component is based on the "TeeChart" library, which is included in Delphi distribution kit. One can also use the "TeeChartPro" library, which can be obtained separately. Let us illustrate a simple construction of a diagram using the following example. To perform this, we would need the "country.db" table from the "DBDEMOS" demo database distribution kit. The table contains data about countries, their area and population:
Name | Area | Population
Argentina | 2 777 815 | 32 300 003
Bolivia | 1 098 575 | 7 300 000
.
Let us create a new project in Delphi. Put the "TTable," "TfrxDBDataSet," and "TfrxReport" components on the form and then customize them: Table1: DatabaseName = 'DBDEMOS' TableName = 'coutry.db' frxDBDataSet1: DataSet = Table1 UserName = 'Country' Let us enter the report designer and connect the data source in the "Report|Data" window. After that, put the "Diagram" object to the report list: Let us set the object size (18x8 cm). To customize the object, call its editor by double-clicking on it. The following items are denoted by figures in the picture: 1 diagram structure. Diagram can contain either one or several series. 2 object inspector, which displays the properties of the element selected in the window. Thus, you can perform tweaking of the diagram properties. 3 toolbar for connection the series to data; it is activated as soon as the series in the window 1 are selected. During the first activation, the editor window will contain an image shown in the picture. The first thing to be done is to add one or several series (one series in our example). To perform this, click the button and select the pie diagram in the menu: As you can see, there are eight different types of series available. After adding the series, the bar 3 becomes active. Here you should specify, which data should be used for plotting. First of all, let us select the data set in the "Data set" pulldown. Fill the "X values" and "Y values" fields in the following way (they can also be selected from the pulldowns): It is necessary to note here, that X-axis values can be of any type (string, for example), since they are informational. However, the Y-axis values must rigorously be of figure type. In our case (with circle diagram) the X-axis values are used for comments of inscriptions displaying, while only the Y-axis values are used for the diagram construction. Let us close the setting (click "OK" to close the editor), and then start report construction: What can be improved in this report? First of all, it would be nice to sort values in descending order. Again, we enter the diagram editor and select the series in the upper part of the window. Now we select the required sorting mode: If starting the report now, we would see that the data in the explaining table is sorted.