1 (edited by madbit71 2023-07-05 18:08:24)

Topic: -SOLVED- Piechart - change color

Hello everyone, I would like to know how to change the color of the sectors of a pie chart, for example instead of blue and yellow, display them green and red.
Thank you.

Re: -SOLVED- Piechart - change color

Hello Madbit71

A long time ago with Delphi 7, I did like this

Form1. Chart1.Series[0].Color := $FF0000; // hexadecimal value of the color

If you have several series:

  Form1. Chart1.Series[0].Color := clGreen; // Windows color name
  Form1. Chart1.Series[1].Color := clYellow;

It had worked. I would have to find my old app, but Delphi 7 and windows 10 don't go well together (you have to tweak a bit)

JB

Re: -SOLVED- Piechart - change color

Hi

http://myvisualdatabase.com/forum/viewt … 442#p47442

Re: -SOLVED- Piechart - change color

Thanks jean.brezhonek and sparrow,
I had read that post but I couldn't apply it to a pie chart.
I tried based on an example from Derek, derekpiechart which I attach, in which only one series is added; if I insert the color at the end of line 35:
...
if ValidInt(cfsexValue) then Chart.Series[0].AddXY(x,strtoint(cfsexValue),sexvalue,clred);
...
all parts of the pie chart are colored red.

Post's attachments

Attachment icon derek piechart.rar 490.48 kb, 66 downloads since 2023-07-05 

Re: -SOLVED- Piechart - change color

Of course, it won't work all at once.
You need to put your hands a little and turn your head on.
Pay attention that you have a cycle and if you put one value RED in the cycle, then it will be red for everything.
It can be done like this.

Post's attachments

Attachment icon derek piechart cust color.zip 329.68 kb, 101 downloads since 2023-07-05 

Re: -SOLVED- Piechart - change color

Thanks sparrow,
it's perfect and I never could have done it without your help...especially in such an elegant way.