Need to add and change custom color for PIE chart

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Need to add and change custom color for PIE chart

Post by Abhishek_Paul »

I am creating a pie chart and using a color palette "Semitransparent". I am getting the output in the attached file.
Chart.png
Chart.png (17.84 KiB) Viewed 3782 times
I need to change palette color order or add custom color and give first preference order.

Please suggest which property I need to change to get the desired output.
e.g. I need to set two colors "Red" and "green" for success and failure status in the PIE chart. How do set the color property for this?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need to add and change custom color for PIE chart

Post by jvierra »

Colors are set based on the value of the items in the chart. YOu have to set the color for each item.

Here is a good place to start learning the chart control. https://www.sapien.com/blog/2011/05/05/ ... powershell
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Re: Need to add and change custom color for PIE chart

Post by Abhishek_Paul »

Thanks, Jivierra.
I have already referred to that article and I am able to get the output. However, I am not able to set the custom color for each value as per my need.
Which property needs to be changed to set the custom color or reorder the color palette.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need to add and change custom color for PIE chart

Post by jvierra »

As best I can remember each item in the chart has a color value which you can set.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need to add and change custom color for PIE chart

Post by jvierra »

On the "Series Collection Editor" you can set the palette for each defined series.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need to add and change custom color for PIE chart

Post by jvierra »

If you are trying to use the Chart Control sets then this property does not work. The base code is incorrect and fails to crate a pallet set before assigning to the "PalletCustomColors" property. You can add this in the form load event and set the colors you want.

$custompallet = <your chart object>.PalletCustomColors = [System.Drawing.Color[]]::New(16)
Now assign colors to each entry.

Set the pallet for the series to "None" and the custom palette should show.
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Re: Need to add and change custom color for PIE chart

Post by Abhishek_Paul »

Hi Jivierra,
I was going through some article. There it says it's possible to set the maximum and minimum value a colour.

Code: Select all

# Find point with max/min values and change their colour 
$maxValuePoint = $Chart.Series["Data"].Points.FindMaxByValue() 
$maxValuePoint.Color = [System.Drawing.Color]::Red


$minValuePoint = $Chart.Series["Data"].Points.FindMinByValue() 
$minValuePoint.Color = [System.Drawing.Color]::Green
How Can I use this in my Powershell studio pie chart?
I tried to change the chart variable and series name . but it doesn't work.
User avatar
Abhishek_Paul
Posts: 24
Last visit: Fri Jun 15, 2018 2:04 am

Re: Need to add and change custom color for PIE chart

Post by Abhishek_Paul »

I am attaching the psf file for your reference. Please help me change the custom color.
TestPie.psf
(40.59 KiB) Downloaded 193 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Need to add and change custom color for PIE chart

Post by jvierra »

You will have to create your own custom chart and manage the data points in code.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked