Back to Devexpress

TcxGridChartDiagramLegendItemCustomDrawEvent Type

vcl-cxgridchartview-d60e2e52.md

latest4.4 KB
Original Source

TcxGridChartDiagramLegendItemCustomDrawEvent Type

The procedural type for legend item draw events.

Declaration

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

Parameters

NameTypeDescription
SenderTcxGridChartDiagram

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.TrueBuilt-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:

delphi
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;
cpp
#include "cxGrid.hpp" // Declares the TcxGrid control
#include "cxGridDBChartView.hpp" // Declares the TcxGridDBChartView class
#include "StrUtils.hpp" // Declares the ContainsText function

// Add the following linker directives to the corresponding CPP source file:
#pragma link "cxGrid" // Required to use cxGrid.hpp declarations
#pragma link "cxGridDBChartView" // Required to use cxGridDBChartView.hpp declarations

void __fastcall TMyForm::cxGrid1ChartViewDiagramStackedColumnCustomDrawLegendItem(
  TcxGridChartDiagram *Sender, TcxCanvas *ACanvas,
  TcxGridChartLegendItemViewInfo *AViewInfo, bool &ADone)
{
  if(ContainsText(dynamic_cast<TcxGridDBChartSeries*>(AViewInfo->Series)->DataBinding->FieldName, "Female"))
    ACanvas->FillRect(AViewInfo->Bounds, clWebLightGreen);
  else
    ACanvas->FillRect(AViewInfo->Bounds, clWebLightCoral);
}

Direct TcxGridChartDiagramLegendItemCustomDrawEvent Type Reference

The TcxGridChartDiagram.OnCustomDrawLegendItem event references the TcxGridChartDiagramLegendItemCustomDrawEvent procedural type.

See Also

TcxGridChartDiagramLegendCustomDrawEvent Procedural Type

TcxGridChartLegendItemCustomDrawEvent Procedural Type

cxGridChartView Unit