Stacked Column 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 8 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
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Stacked Column Chart

Post by boyddt_co »

I am looking to create a stacked column chart and I'm struggling mentally. my data set is below.and I'm trying to figure out how to set it up in an array that the chart can use.

This is a snippet of the code. If you need more to see what I'm doing I can add to it.

# add data to chart
$Cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539; Paris=2188500}
[void]$Chart.Series.Add("Data")
$Chart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::stackedcolumn
$Chart.Series["Data"].Points.DataBindXY($Cities.Keys, $Cities.Values)


Operator OpCount dt
George 5 10/20/2015 12:00:00 AM
George 6 10/21/2015 12:00:00 AM
George 2 10/22/2015 12:00:00 AM
George 3 10/23/2015 12:00:00 AM
George 5 10/26/2015 12:00:00 AM
Sam 5 10/20/2015 12:00:00 AM
Sam 3 10/21/2015 12:00:00 AM
Sam 6 10/22/2015 12:00:00 AM
Sam 4 10/23/2015 12:00:00 AM
Sam 3 10/26/2015 12:00:00 AM
Sarah 6 10/20/2015 12:00:00 AM
Sarah 8 10/21/2015 12:00:00 AM
Sarah 6 10/22/2015 12:00:00 AM
Sarah 5 10/23/2015 12:00:00 AM
Sarah 7 10/26/2015 12:00:00 AM
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stacked Column Chart

Post by jvierra »

There doesn't appear to ba any relationship between your data and the chart.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stacked Column Chart

Post by jvierra »

Here is some background on the chart control.

https://www.sapien.com/blog/2011/05/05/ ... owershell/
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Re: Stacked Column Chart

Post by boyddt_co »

jvierra wrote:There doesn't appear to ba any relationship between your data and the chart.
and therein lies the problem...

I can't find anything that explains how to construct the code for a stacked column chart. I've looked through MSN and maybe it is because I'm slow but didn't see much there either and the link that you sent me only talks about bar & pie charts.

Any help would be appreciated.

David
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stacked Column Chart

Post by jvierra »

Just set the chart to stacked bar.

Here are all f the possible type codes.
https://msdn.microsoft.com/en-us/libra ... .110).aspx
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Stacked Column Chart

Post by dan.potter »

I hear you David, charts for me had my head spinning.

For stacked add two series. Start with static numbers first. Here is something I did for MS office subcriptions.
  1. $Chart2.Titles["Title1"].Text = "Used $usedlic of $purchasedlic allocated licenses."
  2.        
  3.         $Chart2.Series["Series1"].Points.Clear()
  4.         $Chart2.Series["Series2"].Points.Clear()
  5.        
  6.         $Chart2.Series["Series1"].Points.AddY($usedlic)
  7.         $Chart2.Series["Series2"].Points.AddY($remaininglic)
  8.        
  9.         $maxValue = $Chart2.Series["Series1"].Points.FindMaxByValue()
  10.         $maxValue.Color = [System.Drawing.Color]::DodgerBlue
  11.         $minValue = $Chart2.Series["Series2"].Points.FindMinByValue()
  12.         $minValue.Color = [System.Drawing.Color]::FloralWhite
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Stacked Column Chart

Post by dan.potter »

ok then.
Attachments
chart.psf
(27.25 KiB) Downloaded 253 times
chart.psf
(27.25 KiB) Downloaded 202 times
chart.psf
(27.25 KiB) Downloaded 199 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Stacked Column Chart

Post by jvierra »

The Load-Chart function has a chartstyle parameter. Just set it to StackedBar. THat is all that is required. Everything else will be done automatically.

If you want to manually build charts from scratch then the same ius true. Set ChartType on a series to StackedBar.
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

Re: Stacked Column Chart

Post by boyddt_co »

Dan, thank you for the help, I'll play with it tomorrow and see how I do.
This topic is 8 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