Skip to main content

Create and Delete Series

  • 3 minutes to read

This topic covers series creation and deletion within a Chart View.

Every Chart View provides the Series properties and this maintains indexed collections of the data series created within the View. The Series properties address the items of the TcxGridChartSeries and TcxGridDBChartSeries classes.

You can refer to the Views and Items in Chart Views topics to learn more about the Chart View and its item types.

In this topic, we will use the CARS table that is shipped with the EQGrid demos and contains information on various cars.

There are two methods that you can employ to create data series within a Chart View.

Creating Series At Runtime

This method is applicable to data-aware and non data-aware Views. The CreateSeries method creates a new data series and adds it to the Series collection. In a data-aware View, CreateSeries does not bind the series to a specific field in the bound dataset. You need to do this manually by using the DataBinding property of a series.

The following code creates a series within the data-aware Chart View named chvDBCars and links it to the CYL field in the CARS table (linked via the View’s DataController.DataSource property).

var
  ADBSeries: TcxGridDBChartSeries;
//...
  ADBSeries := chvDBCars.CreateSeries;
  ADBSeries.DataBinding.FieldName := 'CYL';

Creating Series At Design Time

At design time, you can create series within a Chart View via the Structure Navigator and Component Editor. Please refer to the Component Editor topic to learn more about these facilities.

In the Structure Navigator, click the label of the Chart View and activate the Component Editor by clicking on the Customize… button of the Structure Navigator. The Component Editor has a Series tab on the right. Clicking the Add… button in a non data-aware View simply adds a series.

Clicking the Add… button in a data-aware View which is already linked to an active dataset displays a dropdown menu that lists all the numeric fields in the bound data source. You can specify the fields for which the series need to be created or create an unbound series by choosing the ‘Blank‘ menu item.

Note

The fields for which the series have been created in the View are displayed as checked in the dropdown menu. You can delete the series from the View by unchecking the corresponding field in the dropdown menu. Use the Move Up and Move Down buttons to specify the order in which the series will be plotted in the View. This modifies the index of the series within the View’s Series collection.

Deleting Series

To delete a series at runtime, you just need to invoke its destructor. The following code is used to dispose of the chvDBCarsSeriesCyl series from the Chart View:

chvDBCarsSeriesCyl.Free;

The View’s ClearSeries method allows you to destroy all the created series within a Chart View.

chvDBCars.ClearSeries;

At design time, use the Component Editor to delete a series. To delete a specific series, select it and then click the Delete button.

To delete all the series within a Chart View, click the Select All button and then click the Delete button.

See Also