# Help with Building a BarChart using .NET

**URL:** <https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719>\
**Category:** PowerShell Help\
**Created:** [July 28, 2020, 10:31am UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719 "2020-07-28T10:31:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tluizzi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tluizzi/32/1033_2.png) [@tluizzi](https://forums.powershell.org/u/tluizzi)\
**Post date:** [July 28, 2020, 10:31am UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719/1 "2020-07-28T10:31:59Z")

</div>

Help with Building a BarChart using .NET

Hello, I successfully built a two series bar chart using [Building a Chart Using PowerShell and Chart Controls | Learn Powershell | Achieve More](https://learn-powershell.net/2016/09/18/building-a-chart-using-powershell-and-chart-controls/), as a reference. However the axis X data labels will not show for the minor tick labels, only the labels are shown next to the major tick labels.

&nbsp;

```
PS C:\$SummaryData

OUName Enabled Disabled Total
------ ------- -------- -----
OU1 400 150 550
OU2 374 3 377
OU3 125 2 127
OU4 98 0 98
OU5 83 0 83
OU6 48 0 48
OU7 35 7 42
OU8 38 1 39
OU9 1 29 30
OU10 25 0 25
Add-Type -AssemblyName System.Windows.Forms.DataVisualization

$Chart = New-Object System.Windows.Forms.DataVisualization.Charting.Chart

$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea

$SeriesEnabled = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series

$SeriesDisabled = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series

$ChartTypes = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]

$SeriesEnabled.ChartType = $ChartTypes::Bar

$SeriesDisabled.ChartType = $ChartTypes::Bar

$Chart.Series.Add($SeriesEnabled)

$Chart.Series.Add($SeriesDisabled)

$Chart.ChartAreas.Add($ChartArea)

# Creates System.Arrays

$SummaryX= @(foreach ($X in $SummaryData.OUName) {

$X.ToString()

})

$SummaryY1= @(foreach ($Y1 in $SummaryData.Enabled) {

$Y1.ToString()

})

$SummaryY2= @(foreach ($Y2 in $SummaryData.Disabled) {

$Y2.ToString()

})

#Rename Series and assignes X and Y Points

$Chart.Series['Series1'].Name = "Enabled"

$Chart.Series['Enabled'].Points.DataBindXY($SummaryX, $SummaryY1)

$Chart.Series['Series2'].Name = "Disabled"

$Chart.Series['Disabled'].Points.DataBindXY($SummaryX, $SummaryY2)

#Create data labels on chart

$Chart.Series["Enabled"].Label = "#VALY"

$Chart.Series["Disabled"].Label = "#VALY"

#Change colors

$Chart.Palette = [System.Windows.Forms.DataVisualization.Charting.ChartColorPalette]::None

$Chart.PaletteCustomColors = @( [System.Drawing.Color]::Pink, [System.Drawing.Color]::LightGreen )

#Chart's height

$Chart.Width = 600

$Chart.Height = 800

$Chart.BackColor = [System.Drawing.Color]::White

#Chart Legend

$Legend = New-Object System.Windows.Forms.DataVisualization.Charting.Legend

$Legend.IsEquallySpacedItems = $True

$Legend.BorderColor = 'Black'

$Chart.Legends.Add($Legend)

$Chart.SaveImage(".\$(Get-Date -Format 'yyyyMMdd')_SummaryChartTest.png","png")

I think I have to add or re-set the tickmarkintervals (the default is 0):

TickMark = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.TickMark
$TickMark.Interval = 1
```

I’ll try to upload an image of my chart. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![tluizzi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tluizzi/32/1033_2.png) [@tluizzi](https://forums.powershell.org/u/tluizzi)\
**Post date:** [July 28, 2020, 12:50pm UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719/2 "2020-07-28T12:50:46Z")

</div>

I got it:

```
$chart.ChartAreas.AxisX.Interval = 1
```

I would greatly appreciate it if someone could provide resources on using Powershell with new .NET objects . I stumbled upon an old Pluralsight course, “Everyday PowerShell for Developers,” by Jim Christopher. However, any other articles , courses, or books would be awesome. Not currently looking to become an expert with .NET, just would like enough knowledge on how to understand and navigate through the [https://docs.microsoft.com/](https://docs.microsoft.com/) (should I again need to create a custom System.Windows.Forms.DataVisualization.Charting.Chart object).

Combing through various blogs and forums on how to do simple things like changing the color or adjusting the labels is a real time-waster.

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![grokkit](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grokkit/32/970_2.png) [@grokkit](https://forums.powershell.org/u/grokkit)\
**Post date:** [July 29, 2020, 7:19am UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719/3 "2020-07-29T07:19:11Z")

</div>

Please stop submitting your topics multiple times. You are creating a mess that I have to clean up.

---

<div class="post-metadata">

**Author:** ![tluizzi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tluizzi/32/1033_2.png) [@tluizzi](https://forums.powershell.org/u/tluizzi)\
**Post date:** [July 30, 2020, 6:22am UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719/4 "2020-07-30T06:22:06Z")

</div>

[quote quote=245667]Please stop submitting your topics multiple times. You are creating a mess that I have to clean up.

[/quote]  
Thanks for fixing my post - I appreciate it.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/help-with-building-a-barchart-using-net/14719/5 "2024-05-16T20:29:07Z")

</div>


