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.
Locked
User avatar
Abhishek_Paul
Posts: 24
Joined: Thu Apr 27, 2017 7:51 am

Need to add and change custom color for PIE chart

Post by Abhishek_Paul » Mon Oct 30, 2017 7:34 am

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 1683 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: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 30, 2017 7:55 am

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
Joined: Thu Apr 27, 2017 7:51 am

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

Post by Abhishek_Paul » Mon Oct 30, 2017 8:30 am

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: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 30, 2017 8:32 am

As best I can remember each item in the chart has a color value which you can set.

jvierra
Posts: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 30, 2017 8:42 am

On the "Series Collection Editor" you can set the palette for each defined series.

jvierra
Posts: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 30, 2017 10:11 am

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
Joined: Thu Apr 27, 2017 7:51 am

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

Post by Abhishek_Paul » Mon Oct 30, 2017 12:21 pm

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
Joined: Thu Apr 27, 2017 7:51 am

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

Post by Abhishek_Paul » Mon Oct 30, 2017 12:40 pm

I am attaching the psf file for your reference. Please help me change the custom color.
TestPie.psf
(40.59 KiB) Downloaded 75 times

jvierra
Posts: 14068
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 30, 2017 12:44 pm

You will have to create your own custom chart and manage the data points in code.

Locked