Page 1 of 1

Changing Series Color

Posted: Wed Jan 24, 2007 11:50 am
by 9242408
I seem to be having some trouble changing the color of a series in code. I am dynamically setting up series and just do a color scheme like this:

Code: Select all

chart1.Series[mycol].Color := GetDefaultColor(mycol);
   if chart1.Series[mycol].Color = 16777215 then
           chart1.Series[mycol].Color := 0;

However if the color is white, I want it to be something the user can see since my panel is white. The code seems to execute ok but does not change the color at all.

What are some of the other color schemes to use dynamically?


Thanks,

Tom

Posted: Wed Jan 24, 2007 12:36 pm
by narcis
Hi Tom,

This will depend on the series style you are using as you may need to type cast them to have access to the specific series style properties, as shown in the example below for line series.

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 10 do
  begin
    Chart1.AddSeries(TLineSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin

  for i:=0 to Chart1.SeriesCount - 1 do
  begin
    if (Chart1[i] is TLineSeries) then
    begin
      (Chart1[i] as TLineSeries).LinePen.Color:=RGB(10*i,10*i,10*i);
      Chart1[i].Color:=RGB(10*i,10*i,10*i);
    end
    else
      Chart1[i].Color:=clRed;
  end;

Posted: Wed Jan 24, 2007 3:43 pm
by 9242408
Narcis,

I tried modifying the code a bit to set the color if white to black but it ends up turning all the series colors to black.


Any ideas?


Thanks,

Tom

Posted: Wed Jan 24, 2007 4:09 pm
by narcis
Hi Tom,

Could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post the files at news://www.steema.net/steema.public.attachments or our new upload page at http://www.steema.net/upload/.

Thanks in advance.