Back to Devexpress

TdxChartPalette.GetColorsForIndex(Integer) Method

vcl-dxchartpalette-dot-tdxchartpalette-dot-getcolorsforindex-x28-system-dot-integer-x29.md

latest4.2 KB
Original Source

TdxChartPalette.GetColorsForIndex(Integer) Method

Returns a stored or interpolated palette item for the target index.

Declaration

delphi
function GetColorsForIndex(AIndex: Integer): TdxChartPaletteItem;

Parameters

NameTypeDescription
AIndexInteger

The target palette item index (0 or a positive value):

  • If the specified index is equal to or less than the maximum stored item index, the function returns a stored palette item accessible through the Items property.
  • If the specified index exceeds the maximum stored item index, the function returns a palette item with interpolated colors based on colors of stored palette items.

Note

As the specified index increases, the difference between two adjacent interpolated colors becomes less distinguishable.

|

Returns

TypeDescription
TdxChartPaletteItem

A stored or interpolated palette item.

|

Remarks

While a Chart palette (a TdxChartPalette class descendant instance) stores a finite number of items, you can call the GetColorsForIndex function to generate any number of palette items whose Color and Color2 field values are interpolated based on stored palette item colors.

Code Example: Generate Unique Point Marker Colors

The following code example demonstrates a diagram’s OnGetSeriesPointDrawParameters event handler that uses the Slipstream predefined palette to generate unique fill colors for all point markers in the Europe series:

delphi
procedure TFeaturesDemoMainForm.cdLineGetSeriesPointDrawParameters(
  Sender: TdxChartCustomDiagram;
  AArgs: TdxChartGetSeriesPointDrawParametersEventArgs);
var
  ALineDrawParameters: TdxChartLineSeriesPointDrawParameters;
  APalette: TdxChartPalette;
  APaletteItem: TdxChartPaletteItem;
begin
  APalette := TdxChartStandardPaletteRepository.FindPalette('Slipstream');
  if AArgs.SeriesPoint.Series.Caption = 'Europe' then
  begin
    if AArgs.DrawParameters.ClassType <> TdxChartLineSeriesPointDrawParameters then Exit;
    ALineDrawParameters := AArgs.DrawParameters as TdxChartLineSeriesPointDrawParameters;
    APaletteItem := APalette.GetColorsForIndex(AArgs.SeriesPoint.Index);
    ALineDrawParameters.MarkerAppearance.FillOptions.Color := APaletteItem.Color;
  end;
end;
cpp
void __fastcall TMyForm::cdLineGetSeriesPointDrawParameters(TdxChartCustomDiagram *Sender
   TdxChartGetSeriesPointDrawParametersEventArgs *AArgs)
{
  TdxChartLineSeriesPointDrawParameters *ALineDrawParameters;
  TdxChartPalette *APalette;
  TdxChartPaletteItem *APaletteItem;
// ...
  APalette = TdxChartStandardPaletteRepository::FindPalette("Slipstream");
  if(AArgs->SeriesPoint->Series->Caption == "Europe")
  {
    if(AArgs->DrawParameters->ClassType() != __classid(TdxChartLineSeriesPointDrawParameters)) { return; }
    ALineDrawParameters = dynamic_cast<TdxChartLineSeriesPointDrawParameters*>(AArgs->DrawParameters);
    APaletteItem = APalette->GetColorsForIndex(AArgs->SeriesPoint->Index);
    ALineDrawParameters->MarkerAppearance->FillOptions->Color = APaletteItem->Color;
  }
}

See Also

TdxChartPalette.Items Property

TdxChartUserPalette.Items Property

TdxChartCustomDiagram.OnGetSeriesPointDrawParameters Event

TdxChartPalette Class

TdxChartPalette Members

dxChartPalette Unit