Skip to main content
All docs
V25.1
  • TdxChartPaletteRepository.CreateItem(string,TdxChartPaletteItems) Method

    Creates a new user palette populated with specified colors.

    Declaration

    function CreateItem(const AName: string; AColors: TdxChartPaletteItems): TdxChartUserPalette; overload;

    Parameters

    Name Type Description
    AName string

    The name of the created user palette.

    The AName parameter value initializes the palette’s Name property.

    AColors TdxChartPaletteItems

    The array of items used to populate the created palette.

    Returns

    Type Description
    TdxChartUserPalette

    The created user palette.

    Remarks

    Call the CreateItem function to create a new user palette with the specified name and populate the palette with colors. The CreateItem function can be useful if you need to use an existing palette as the base for new custom palettes as demonstrated in the code example below.

    Code Example: Create Custom Palettes Based on Standard Palettes

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

    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;
    

    VCL Chart Control: An Example of a Custom Palette Derived from a Standard Palette

    See Also