Page 1 of 1

Change the color of a series

Posted: Sat Sep 13, 2008 12:21 pm
by 10048706
Hi,
How can I change the color of a series, If we have explictly given color for each bar.

I had used the following code, If didn’t have any effect on the chart

Added the bar to chart:

Code: Select all

Chart1.AddSeries(TBarSeries);
  Chart1.Series[0].Add(-50,'Test1',clRed);
  Chart1.Series[0].Add(-25,'Test2',clRed);
  Chart1.Series[0].Add(0,'Test3',clgreen);
  Chart1.Series[0].Add(25,'Test4',clgreen);
  Chart1.Series[0].Add(50,'Test4',clgreen);
Code to change the color:

Code: Select all

Chart1.Series[0].Color :=  clblue;
Even coloreach doesn’t have any effect.

Kindly advice. :(

Thanks,
Geetha

Posted: Mon Sep 15, 2008 8:22 am
by narcis
Hi Geetha,

I'm afraid this is a bug. I've added it (TV52013394) to the defect list to be fixed for next releases.

The only solution I can think of is "reseting" ValueColor's array like this:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.AddSeries(TBarSeries.Create(self));
  Chart1[0].Add(-50,'Test1',clRed);
  Chart1[0].Add(-25,'Test2',clRed);
  Chart1[0].Add(0,'Test3',clgreen);
  Chart1[0].Add(25,'Test4',clgreen);
  Chart1[0].Add(50,'Test4',clgreen);

  for i:=0 to Chart1[0].Count-1 do
    Chart1[0].ValueColor[i]:=clTeeColor;

  Chart1[0].ColorEachPoint:=false;
  Chart1[0].Color:=clBlue;
end;

Posted: Fri Feb 20, 2009 3:43 pm
by narcis
Hi Geetha,

As an update, this issue has been fixed for the next maintenance release so that code snippet below will draw all bars blue.

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries.Create(self));
  Chart1[0].Add(-50,'Test1',clRed);
  Chart1[0].Add(-25,'Test2',clRed);
  Chart1[0].Add(0,'Test3',clgreen);
  Chart1[0].Add(25,'Test4',clgreen);
  Chart1[0].Add(50,'Test4',clgreen);

  Chart1[0].ColorEachPoint:=false;
  Chart1[0].Color:=clBlue;
  //(Chart1[0] as TBarSeries).BarBrush.Color:=clBlue;
end;

Posted: Mon Feb 23, 2009 11:53 am
by narcis
Hi Geetha,

Sorry for posting contradictory information but one of my colleagues in the technical department brought to my attention that the fix would break existing functionality and also made me aware that's expected behaviour considering series design. Therefore the only option here is reseting colours array as discussed before.

I'd like to apologise for any inconvenience caused.