Created
December 2, 2014 16:41
-
-
Save constructor-igor/cec9e7fdb685ef7628f1 to your computer and use it in GitHub Desktop.
Problematic powershell chart sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Test Data | |
#$Data=("8/15/2014",3091),("8/14/2014",240),("8/13/2014",519),("8/12/2014",622),("8/11/2014",2132),("8/10/2014",1255),("8/9/2014",3240)|ForEach{[PSCustomObject][Ordered]@{'Date_to_Display'=$_[0];'Number_of_Computers'=$_[1]}} | |
$xlConditionValues=[Microsoft.Office.Interop.Excel.XLConditionValueTypes] | |
$xlTheme=[Microsoft.Office.Interop.Excel.XLThemeColor] | |
$xlChart=[Microsoft.Office.Interop.Excel.XLChartType] | |
$xlIconSet=[Microsoft.Office.Interop.Excel.XLIconSet] | |
$xlDirection=[Microsoft.Office.Interop.Excel.XLDirection] | |
$xl = new-object -ComObject Excel.Application | |
$wb = $xl.workbooks.add() | |
$ws = $wb.activesheet | |
$xl.Visible = $true | |
[array] $dataX = 0, 1, 2, 3, 4 | |
[array] $dataY = 0.9, 0.5, 0.2, 0.9, 0.99 | |
$counter = 0 | |
$dataX | ForEach-Object { | |
$counter++ | |
$ws.cells.Item($counter, 1) = $_ | |
} | |
$counter = 0 | |
$dataY | ForEach-Object { | |
$counter++ | |
$ws.cells.Item($counter, 2) = $_ | |
} | |
#Populate test data onto worksheet | |
#$Data |ConvertTo-CSV -NoTypeInformation -Delimiter "`t"| c:\windows\system32\clip.exe | |
$ws.Range("A1").Select | Out-Null | |
#$ws.paste() | |
#$ws.UsedRange.Columns.item(1).numberformat = "dddd, mmm dd, yyyy" | |
$ws.UsedRange.Columns.AutoFit() |Out-Null | |
#Create Chart | |
$chart=$ws.Shapes.AddChart().Chart | |
$chart.chartType=$xlChart::xlLine | |
#modify the chart title | |
$chart.ChartTitle.Text = "Number of Computers" | |
$ws.shapes.item("Chart 1").top=40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment