Page 1 of 1

ColorEachPoint and Gradient?

Posted: Mon Aug 20, 2012 8:33 pm
by 9347097
Hello, is it possible to use BarSeries.ColorEachPoint and have a gradient?

Thanks.

Re: ColorEachPoint and Gradient?

Posted: Tue Aug 21, 2012 12:33 pm
by yeray
Hi,

Yes, you can. Ie:

Code: Select all

  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    FillSampleValues;
    ColorEachPoint:=true;
    BarStyle:=bsRectGradient;
  end;

Re: ColorEachPoint and Gradient?

Posted: Tue Aug 21, 2012 2:34 pm
by 9347097
Yeray, I should have mentioned that I'm specifying the colors - positive values in green and negative in red, but a gradient version of each color. So I have:

Code: Select all

      if series.ColorEachPoint then
        if y < y0 then
          color := clRed
        else
          color := clGreen
      else
        color := clDefault;
      series.AddXY(x, y, '', color);
Where would you supply the 2nd color for the gradient?

Thanks,
Jim

Re: ColorEachPoint and Gradient?

Posted: Wed Aug 22, 2012 7:36 am
by yeray
Hi Jim,
Jim Green wrote:Where would you supply the 2nd color for the gradient?
You should set the series' Gradient.StartColor property.
However this is a color for the whole series. If you want to set a different StartColor for each point, you could use the OnGetPointerStyle/OnGetBarStyle event to change that color each time a point/bar is going to be drawn.

Code: Select all

Procedure TForm1.GetBarStyle(Sender:TCustomBarSeries; ValueIndex:Integer; var TheBarStyle:TBarStyle);
begin
  Sender.Gradient.StartColor:=ApplyBright(Sender.ValueColor[ValueIndex], 128);
end;