Skip to main content

TcxGridChartDiagramLegendItemCustomDrawEvent Type

The procedural type for legend item draw events.

Declaration

TcxGridChartDiagramLegendItemCustomDrawEvent = procedure(Sender: TcxGridChartDiagram; ACanvas: TcxCanvas; AViewInfo: TcxGridChartLegendItemViewInfo; var ADone: Boolean) of object;

Parameters

Name Type Description
Sender TcxGridChartDiagram

The grid Chart diagram that raised the legend item draw event.

ACanvas TcxCanvas

Provides access to the target legend item’s canvas.

You can call draw methods accessible through the ACanvas parameter to display custom content within the target legend item. Use the ViewInfo parameter to obtain additional information required to draw content, such as legend item boundaries.

AViewInfo TcxGridChartLegendItemViewInfo

Returns information required to identify and draw the processed legend item.

Use the AViewInfo.Series property to identify the currently processed legend item. To obtain calculated legend item boundaries, use the AViewInfo.Bounds field.

ADone Boolean

Specifies if the custom draw event handler overrides or complements built-in draw routines for the target legend item:

False
Default. Built-in draw routines display the processed legend item according to active skin and appearance settings.
True
Built-in draw routines are disabled for the processed cell. Use this option if you need to draw a legend item from scratch.

Remarks

A legend item custom draw event occurs every time the grid Chart diagram is about to draw a legend item. You can handle this event to change the appearance of individual legend items depending on specific conditions in your application.

Code Example: Highlight Legend Items

The following code example fills background with two colors for legend items with different names:

uses
  cxGrid,  // Declares the TcxGrid control
  cxGridDBChartView,  // Declares the TcxGridDBChartView class
  StrUtils;  // Declares the ContainsText function
// ...

procedure TMyForm.cxGrid1ChartViewDiagramStackedColumnCustomDrawLegendItem(
  Sender: TcxGridChartDiagram; ACanvas: TcxCanvas;
  AViewInfo: TcxGridChartLegendItemViewInfo; var ADone: Boolean);
begin
  if ContainsText((AViewInfo.Series as TcxGridDBChartSeries).DataBinding.FieldName, 'Female')  then
    ACanvas.FillRect(AViewInfo.Bounds, clWebLightGreen)
  else
    ACanvas.FillRect(AViewInfo.Bounds, clWebLightCoral);
end;

VCL Data Grid: Legend Items with Custom Background

Direct TcxGridChartDiagramLegendItemCustomDrawEvent Type Reference

The TcxGridChartDiagram.OnCustomDrawLegendItem event references the TcxGridChartDiagramLegendItemCustomDrawEvent procedural type.

See Also