PDA

View Full Version : Powershell and charts ?!



alanrenouf
08-05-2008, 03:05 AM
Hi,

I have managed to add a piechart to a word document using the following code, but I cant manage to get the pie chart to have percentage values, this is available using the .HasPercentage = True value but I cant get it right, can anyone help ?

Thanks


$msWord = New-Object -Com Word.Application
# Create Word Doc
$wordDoc = $msWord.Documents.Add()
# Make word visible (optional)
$msWord.Visible = $true
# Activate the new document
$wordDoc.Activate()

$Caption = "Simple Example"

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 18
$c.HasTitle = "True"
$c.HasLegend = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-Process | foreach-object {
$categories += $_.Name
$values += $_.CPU * 1
}

$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\PIE.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)

$objSelection = $msWord.Selection
$msword.Selection.EndKey(6)
$objSelection.TypeParagraph()
$msWord.Application.Selection.InlineShapes.AddPicture($filename) > Null