Add ShowPercent, ShowCategory and NoLegend switches

This commit is contained in:
dfinke
2015-12-26 14:29:24 -05:00
parent e1dd7fcbde
commit 5bcced2b7c
3 changed files with 59 additions and 379 deletions

View File

@@ -1,12 +1,15 @@
function DoChart {
param(
$targetData,
param(
$targetData,
$title,
$chartType
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType,
[Switch]$NoLegend,
[Switch]$ShowCategory,
[Switch]$ShowPercent
)
if($targetData[0] -is [System.ValueType]) {
$chart = New-ExcelChart -YRange "A1:A$($targetData.count)" -Title $title -ChartType $chartType
$chart = New-ExcelChart -YRange "A1:A$($targetData.count)" -Title $title -ChartType $ChartType
} else {
$xyRange = Get-XYRange $targetData
@@ -16,7 +19,8 @@ function DoChart {
$Y = $xyRange.YRange.ExcelColumn
$YRange = "{0}2:{0}{1}" -f $Y,($targetData.count+1)
$chart = New-ExcelChart -XRange $xRange -YRange $yRange -Title $title -ChartType $chartType
$chart = New-ExcelChart -XRange $xRange -YRange $yRange -Title $title -ChartType $ChartType `
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
}
$xlFile = (New-TemporaryFile).fullname -replace "tmp","xlsx"
@@ -24,26 +28,59 @@ function DoChart {
}
function BarChart {
param($targetData,$title)
function BarChart {
param(
$targetData,
$title,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="BarStacked",
[Switch]$NoLegend,
[Switch]$ShowCategory,
[Switch]$ShowPercent
)
DoChart $targetData $title -ChartType $ChartType `
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
DoChart $targetData $title BarStacked
}
function PieChart {
param($targetData,$title)
DoChart $targetData $title Pie
function PieChart {
param(
$targetData,
$title,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="PieExploded3D",
[Switch]$NoLegend,
[Switch]$ShowCategory,
[Switch]$ShowPercent
)
DoChart $targetData $title -ChartType $ChartType `
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
}
function LineChart {
param($targetData,$title)
function LineChart {
param(
$targetData,
$title,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="Line",
[Switch]$NoLegend,
[Switch]$ShowCategory,
[Switch]$ShowPercent
)
DoChart $targetData $title -ChartType $ChartType `
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
}
DoChart $targetData $title Line
}
function ColumnChart {
param($targetData,$title)
DoChart $targetData $title ColumnStacked
}
function ColumnChart {
param(
$targetData,
$title,
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType="ColumnStacked",
[Switch]$NoLegend,
[Switch]$ShowCategory,
[Switch]$ShowPercent
)
DoChart $targetData $title -ChartType $ChartType `
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
}