From d88300032712a62f4fac534fcbb2a2d97028aaa5 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 26 Dec 2015 16:25:50 -0500 Subject: [PATCH] Added ValueFromPipeline to the data parameter --- Charting.ps1 | 54 ++++++++++++++++++++++++++++++++++++---------------- README.md | 6 ++++++ 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Charting.ps1 b/Charting.ps1 index f7fab3a..7cbac92 100644 --- a/Charting.ps1 +++ b/Charting.ps1 @@ -1,11 +1,11 @@ function DoChart { param( $targetData, - $title, - [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType, - [Switch]$NoLegend, - [Switch]$ShowCategory, - [Switch]$ShowPercent + $title, + [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType, + [Switch]$NoLegend, + [Switch]$ShowCategory, + [Switch]$ShowPercent ) if($targetData[0] -is [System.ValueType]) { @@ -25,11 +25,11 @@ function DoChart { $xlFile = (New-TemporaryFile).fullname -replace "tmp","xlsx" $targetData | Export-Excel $xlFile -ExcelChartDefinition $chart -Show -AutoSize - - } +} function BarChart { param( + [Parameter(ValueFromPipeline=$true)] $targetData, $title, [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="BarStacked", @@ -38,13 +38,18 @@ function BarChart { [Switch]$ShowPercent ) - DoChart $targetData $title -ChartType $ChartType ` - -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + Begin { $data = @() } + Process { $data += $targetData} - } + End { + DoChart $data $title -ChartType $ChartType ` + -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + } +} function PieChart { param( + [Parameter(ValueFromPipeline=$true)] $targetData, $title, [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="PieExploded3D", @@ -53,12 +58,18 @@ function PieChart { [Switch]$ShowPercent ) - DoChart $targetData $title -ChartType $ChartType ` - -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + Begin { $data = @() } + Process { $data += $targetData} + + End { + DoChart $data $title -ChartType $ChartType ` + -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + } } function LineChart { param( + [Parameter(ValueFromPipeline=$true)] $targetData, $title, [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Line", @@ -67,12 +78,18 @@ function LineChart { [Switch]$ShowPercent ) - DoChart $targetData $title -ChartType $ChartType ` - -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + Begin { $data = @() } + Process { $data += $targetData} + + End { + DoChart $data $title -ChartType $ChartType ` + -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + } } function ColumnChart { param( + [Parameter(ValueFromPipeline=$true)] $targetData, $title, [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="ColumnStacked", @@ -81,6 +98,11 @@ function ColumnChart { [Switch]$ShowPercent ) - DoChart $targetData $title -ChartType $ChartType ` - -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + Begin { $data = @() } + Process { $data += $targetData} + + End { + DoChart $data $title -ChartType $ChartType ` + -NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent + } } \ No newline at end of file diff --git a/README.md b/README.md index f6e5379..69fb5d7 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,13 @@ Known Issues What's new - +#### 12/26/2015 + +* Added `NoLegend`, `Show-Category`, `ShowPercent` for all charts including Pivot Charts +* Updated PieChart, BarChart, ColumnChart and Line chart to work with the pipeline and added `NoLegend`, `Show-Category`, `ShowPercent` + #### 12/17/2015 + These new features open the door for really sophisticated work sheet creation. Stay tuned for a [blog post](http://www.dougfinke.com/blog/) and examples.