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.
Locked
User avatar
boyddt_co
Posts: 75
Joined: Mon Dec 17, 2007 5:50 am

Stacked Column Chart

Post by boyddt_co » Tue Oct 27, 2015 8:47 am

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

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Stacked Column Chart

Post by jvierra » Tue Oct 27, 2015 9:54 am

There doesn't appear to ba any relationship between your data and the chart.

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Stacked Column Chart

Post by jvierra » Tue Oct 27, 2015 9:56 am

Here is some background on the chart control.

https://www.sapien.com/blog/2011/05/05/ ... owershell/

User avatar
boyddt_co
Posts: 75
Joined: Mon Dec 17, 2007 5:50 am

Re: Stacked Column Chart

Post by boyddt_co » Tue Oct 27, 2015 12:29 pm

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

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Stacked Column Chart

Post by jvierra » Tue Oct 27, 2015 12:54 pm

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
Joined: Wed Oct 08, 2014 6:02 am

Re: Stacked Column Chart

Post by dan.potter » Wed Oct 28, 2015 7:46 am

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.

Code: Select all

$Chart2.Titles["Title1"].Text = "Used $usedlic of $purchasedlic allocated licenses."

$Chart2.Series["Series1"].Points.Clear()
$Chart2.Series["Series2"].Points.Clear()

$Chart2.Series["Series1"].Points.AddY($usedlic)
$Chart2.Series["Series2"].Points.AddY($remaininglic)

$maxValue = $Chart2.Series["Series1"].Points.FindMaxByValue()
$maxValue.Color = [System.Drawing.Color]::DodgerBlue
$minValue = $Chart2.Series["Series2"].Points.FindMinByValue()
$minValue.Color = [System.Drawing.Color]::FloralWhite

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: Stacked Column Chart

Post by dan.potter » Wed Oct 28, 2015 8:05 am

ok then.
Attachments
chart.psf
(27.25 KiB) Downloaded 131 times
chart.psf
(27.25 KiB) Downloaded 99 times
chart.psf
(27.25 KiB) Downloaded 96 times

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Stacked Column Chart

Post by jvierra » Wed Oct 28, 2015 8:44 am

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: 75
Joined: Mon Dec 17, 2007 5:50 am

Re: Stacked Column Chart

Post by boyddt_co » Thu Oct 29, 2015 6:53 am

Dan, thank you for the help, I'll play with it tomorrow and see how I do.

Locked