Page 1 of 1

Modifying lines colors in TDBChart

Posted: Thu Jul 12, 2012 5:50 pm
by 9231501
Hi!

I have a TDBChart with a Lines series, and I would like to try different color palletes to find the best one (read, the one that repeats less colors) to be used with the situation when the datasource returns several records (meaning more than 15 lines in the chart).

I tried to use DBChart1.ColorPaletteIndex:=<<some existing index>> but seems to produce no effect at all.

Can someone point me to the correct way of doing this?

Carlos

Re: Modifying lines colors in TDBChart

Posted: Fri Jul 13, 2012 3:17 pm
by yeray
Hola Carlos,

Take a look at the example at "All Features\Welcome !\Aspect\Custom Palettes" in the features demo included with the installation. It shows how to change between the different default palettes and how to create a customized one.

However, the default palettes (and any you can create) have a limited size. If you want to create more series than colors your palette has, you will probably want to reuse the colors in the palette. You could do so as in the following example:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;

  ColorPalettes.ApplyPalette(Chart1, WindowsVistaPalette);

  for i:=0 to 20 do
    with Chart1.AddSeries(TFastLineSeries) do
    begin
      FillSampleValues;
      Color:=Chart1.ColorPalette[i mod Length(Chart1.ColorPalette)-1];
    end;
end;