Back to Devexpress

TdxChartPalette.Items Property

vcl-dxchartpalette-dot-tdxchartpalette-5d37a4fd.md

latest3.7 KB
Original Source

TdxChartPalette.Items Property

Provides indexed access to all explicitly defined (stored) Chart palette items.

Declaration

delphi
property Items[Index: Integer]: TdxChartPaletteItem read; default;

Property Value

TypeDescription
TdxChartPaletteItem

A chart palette item.

|

Remarks

Use the Count property to identify the number of stored palette items accessible through the Items property. You can call the GetColorsForIndex function to obtain stored or interpolated palette items by index.

Code Example: Copy Standard Palette Colors to a User Palette

The following code example creates a custom palette based on one of the predefined palettes and applies the created palette to a Chart control:

delphi
var
  AStandardPalette: TdxChartPalette;
  AChartPalette: TdxChartUserPalette;
  APaletteItems: TdxChartPaletteItems; // A dynamic array of palette items used as a temporary container
  I: Integer;
begin
  AStandardPalette := TdxChartStandardPaletteRepository.FindPalette('Nature Colors');
  if AStandardPalette = nil then Exit;
  SetLength(APaletteItems, AStandardPalette.Count);
  // Copies all colors from the obtained color palette into the defined dynamic array
  for I := 0 to AStandardPalette.Count - 1 do
    APaletteItems[I] := AStandardPalette.Items[I];
  AChartPalette := dxChartPaletteRepository1.CreateItem('My Palette 1', APaletteItems);
  // Replaces the third palette item
  AChartPalette.Items[2] := TdxChartPaletteItem.Create(TdxAlphaColors.Red);
  // Adds a new palette item
  AChartPalette.Count := AChartPalette.Count + 1; // Increments the size of the palette item array
  AChartPalette.Items[AChartPalette.Count - 1] := TdxChartPaletteItem.Create(TdxAlphaColors.LightGreen);
  dxChartControl1.Palette := AChartPalette; // Assigns the created palette to a TdxChartControl instance
end;
cpp
TdxChartPalette *AStandardPalette;
  TdxChartUserPalette *AChartPalette;
  TdxChartPaletteItems *APaletteItems; // A dynamic array of palette items used as a temporary container
  // ...
  AStandardPalette = TdxChartStandardPaletteRepository->FindPalette("Nature Colors");
  if (AStandardPalette == nullptr) { return; }
  SetLength(APaletteItems, AStandardPalette->Count);
  // Copies all colors from the obtained color palette into the defined dynamic array
  for(int i = 0; i < AStandardPalette->Count; i++)
    APaletteItems[i] = AStandardPalette->Items[i];
  AChartPalette = dxChartPaletteRepository1->CreateItem("My Palette 1", APaletteItems);
  // Replaces the third palette item
  AChartPalette->Items[2] = TdxChartPaletteItem(TdxAlphaColors::Red);
  // Adds a new palette item
  AChartPalette->Count = AChartPalette->Count + 1; // Increments the size of the palette item array
  AChartPalette->Items[AChartPalette->Count - 1] = TdxChartPaletteItem(TdxAlphaColors::LightGreen);
  dxChartControl1->Palette = AChartPalette; // Assigns the created palette to a TdxChartControl instance

See Also

TdxChartUserPalette.Items Property

TdxChartPalette Class

TdxChartPalette Members

dxChartPalette Unit