mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-01-07 11:03:31 +00:00
Move help from Comment-based to md. Relocate functions (sans help)
This commit is contained in:
108
Charting/Charting.ps1
Normal file
108
Charting/Charting.ps1
Normal file
@@ -0,0 +1,108 @@
|
||||
function DoChart {
|
||||
param(
|
||||
$targetData,
|
||||
$title,
|
||||
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType,
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$ShowPercent
|
||||
)
|
||||
|
||||
if($targetData[0] -is [System.ValueType]) {
|
||||
$chart = New-ExcelChartDefinition -YRange "A1:A$($targetData.count)" -Title $title -ChartType $ChartType
|
||||
} else {
|
||||
$xyRange = Get-XYRange $targetData
|
||||
|
||||
$X = $xyRange.XRange.ExcelColumn
|
||||
$XRange = "{0}2:{0}{1}" -f $X,($targetData.count+1)
|
||||
|
||||
$Y = $xyRange.YRange.ExcelColumn
|
||||
$YRange = "{0}2:{0}{1}" -f $Y,($targetData.count+1)
|
||||
|
||||
$chart = New-ExcelChartDefinition -XRange $xRange -YRange $yRange -Title $title -ChartType $ChartType `
|
||||
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
|
||||
}
|
||||
|
||||
$xlFile = [System.IO.Path]::GetTempFileName() -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",
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$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",
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$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",
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$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",
|
||||
[Switch]$NoLegend,
|
||||
[Switch]$ShowCategory,
|
||||
[Switch]$ShowPercent
|
||||
)
|
||||
|
||||
Begin { $data = @() }
|
||||
Process { $data += $targetData}
|
||||
|
||||
End {
|
||||
DoChart $data $title -ChartType $ChartType `
|
||||
-NoLegend:$NoLegend -ShowCategory:$ShowCategory -ShowPercent:$ShowPercent
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user