Page 1 of 1

How to set pattern for specific donut slice ?

Posted: Fri May 19, 2023 11:01 am
by 16592320
Hi,

I want to set pattern for specific slice in Donut chart. Is its possible ?

I found UsePatterns property but if set they draw all slices with pattern. But I need specific ones.

So, how to select pattern type, foreground and background colors for specific slise ? Maybe using some event ?

Result should looks like this (made by hand):

Image

Thanks for help !

Re: How to set pattern for specific donut slice ?

Posted: Mon May 29, 2023 12:41 pm
by yeray
Hello,

You can do something similar to the explained here:
TeeChartVCLTest_2023-05-29_14-42-51.png
TeeChartVCLTest_2023-05-29_14-42-51.png (19.25 KiB) Viewed 10806 times

Code: Select all

type TDonutSeriesAccess=class(TDonutSeries);

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TDonutSeries).FillSampleValues(5);

  Chart1.OnAfterDraw:=PatternInDonutSliceAfterDraw;
end;

procedure TForm1.PatternInDonutSliceAfterDraw(Sender: TObject);
var donut: TDonutSeriesAccess;
begin
  if (Chart1.SeriesCount>0) and (Chart1[0] is TDonutSeries) then
  begin
    donut:=TDonutSeriesAccess(Chart1[0]);
    if pie.Count>1 then
    begin
      Chart1.Canvas.Brush.Color:=donut.GetValueColor(1);
      Chart1.Canvas.Brush.Style:=bsFDiagonal;
      donut.DrawPie(1);
    end;
  end;
end;

Re: How to set pattern for specific donut slice ?

Posted: Fri Jun 02, 2023 3:43 pm
by 16592320
Thank you very mush ! I will try !

Re: How to set pattern for specific donut slice ?

Posted: Fri Jun 02, 2023 4:30 pm
by 16592320
Its working perfect ! Thank you very much !