vcl-dxganttcontrolviewchart-7c9a4d54.md
The color-related procedural type for tasks and their baselines in the Chart View.
TdxGanttControlChartViewGetTaskColorEvent = procedure(Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask; var AColor: TColor) of object;
| Name | Type | Description |
|---|---|---|
| Sender | TdxGanttControlChartView |
The Chart View that raised the event.
| | ATask | TdxGanttControlTask |
In the OnGetTaskColor event: The task whose color is about to be changed. This parameter is nil (in Delphi) or nullptr (in C++Builder) if a user creates a task in the chart area with the mouse.
In the OnGetTaskBaselineColor event: The task whose baseline’s color is about to be changed.
| | AColor | TColor |
A system palette color.
|
The following code example demonstrates how to use the OnGetTaskColor event to color all outdated tasks in the Chart View with the red color (clRed):
procedure TMyForm.FormCreate(Sender: TObject);
begin
// Loads a chart from the specified XML file
dxGanttControl1.LoadFromFile('C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\Data\SoftDev.xml');
end;
procedure TMyForm.dxGanttControl1ViewChartGetTaskColor(
Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask;
var AColor: TColor);
begin
// Checks if the inspected task exists and compares its date with the current date
if (ATask <> nil) and (ATask.Finish < Now) then
// Fills outdated tasks with the red color
AColor := clRed;
end;
{
void __fastcall TMyForm::FormCreate(TObject *Sender)
{ // Loads a chart from the specified XML file
dxGanttControl1->LoadFromFile("C:/Users/Public/Documents/DevExpress/VCL/Demos/ExpressGantt Control/Data/SoftwareDevelopment.xml");
}
//---------------------------------------------------------------------------
void __fastcall TMyForm::dxGanttControl1ViewChartGetTaskColor(TdxGanttControlChartView *Sender,
TdxGanttControlTask *ATask, TColor &AColor)
{
// Checks if the inspected task exists and compares its date with the current date
if (ATask != NULL && ATask->Finish < Now())
{
// Fills outdated tasks with the red color
AColor = clRed;
}
}
You can open the installed Baselines Demo and modify its code. The demo is available by the following path:
Delphi C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\Delphi\BaselinesDemo\C++Builder C:\Users\Public\Documents\DevExpress\VCL\Demos\ExpressGantt Control\CBuilder\BaselinesDemo\
The following code example demonstrates how to use the OnGetTaskBaselineColor event to color a baseline in the Chart View with the red color (clRed) if actual dates of its task are shifted:
procedure TBaselinesDemoMainForm.GanttControlViewChartGetTaskBaselineColor(
Sender: TdxGanttControlChartView; ATask: TdxGanttControlTask;
var AColor: TColor);
var
ABaseline: TdxGanttControlTaskBaseline;
begin
// Searches a task baseline by its number
ABaseline := ATask.Baselines.Find(GanttControl.ViewChart.BaselineNumber);
// Checks if the inspected baseline exists and compares its dates with the associated task's actual dates
if (ABaseline <> nil) and (ABaseline.Finish - ABaseline.Start < ATask.Finish - ATask.Start) then
// Fills all baselines that meet the specified conditions with the red color
AColor := clRed;
end;
void __fastcall TBaselinesDemoMainForm::GanttControlViewChartGetTaskBaselineColor(TdxGanttControlChartView *Sender,
TdxGanttControlTask *ATask, TColor &AColor)
{ // Searches a task baseline by its number
TdxGanttControlTaskBaseline* ABaseline = ATask->Baselines->Find(GanttControl->ViewChart->BaselineNumber);
// Checks if the inspected baseline exists and compares its dates with the associated task's actual dates
if ((ABaseline != NULL) && (ABaseline->Finish - ABaseline->Start < ATask->Finish - ATask->Start))
{
// Fills all baselines that meet the specified conditions with the red color
AColor = clRed;
}
}
See Also