From 42d0ad03783304fe04bffdb899934528f802a066 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 20 Mar 2016 22:51:07 -0400 Subject: [PATCH] Add `Plot` function --- Examples/JustCharts/TargetData.csv | 8 ++++++ ImportExcel.psd1 | 2 +- ImportExcel.psm1 | 7 ++++- plot.ps1 | 46 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 Examples/JustCharts/TargetData.csv diff --git a/Examples/JustCharts/TargetData.csv b/Examples/JustCharts/TargetData.csv new file mode 100644 index 0000000..a8c402c --- /dev/null +++ b/Examples/JustCharts/TargetData.csv @@ -0,0 +1,8 @@ +Cost,Date,Name +1.1,1/1/2015,John +2.1,1/2/2015,Tom +5.1,1/2/2015,Dick +11.1,1/2/2015,Harry +7.1,1/2/2015,Jane +22.1,1/2/2015,Mary +32.1,1/2/2015,Liz diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 3cf7149..06335e0 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. -ModuleVersion = '2.1.4' +ModuleVersion = '2.2.0' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 17ac457..93278b2 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -18,7 +18,12 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" . $PSScriptRoot\Get-Range.ps1 . $PSScriptRoot\plot.ps1 -function New-Plot { [psplot]::new() } +function New-Plot { + [OutputType([PSPlot])] + param() + + [psplot]::new() +} function Import-Excel { param( diff --git a/plot.ps1 b/plot.ps1 index f04d629..98be319 100644 --- a/plot.ps1 +++ b/plot.ps1 @@ -24,6 +24,21 @@ class PSPlot { $this.SetChartPosition($yCol) } + Plot($yValues,[string]$options) { + $this.NewChart() + + $xValues = 0..$yValues.Count + + $xCol = 'A' + $yCol = 'B' + + $this.AddDataToSheet($xCol,$yCol,'x','y',$xValues,$yValues) + $this.AddSeries($xCol,$yCol,$yValues) + + $this.SetMarkerInfo($options) + $this.SetChartPosition($yCol) + } + Plot($xValues,$yValues) { $this.NewChart() @@ -33,6 +48,21 @@ class PSPlot { $this.AddDataToSheet($xCol,$yCol,'x','y',$xValues,$yValues) $this.AddSeries($xCol,$yCol,$yValues) + + $this.SetChartPosition($yCol) + } + + Plot($xValues,$yValues,[string]$options) { + $this.NewChart() + + $xCol = 'A' + $yCol = 'B' + + $this.AddDataToSheet($xCol,$yCol,'x','y',$xValues,$yValues) + $this.AddSeries($xCol,$yCol,$yValues) + + $this.SetMarkerInfo($options) + $this.SetChartPosition($yCol) } @@ -91,6 +121,18 @@ class PSPlot { $Series=$this.chart.Series.Add($yRange,$xRange) } + hidden SetMarkerInfo([string]$options) { + $c=$options.Substring(0,1) + $m=$options.Substring(1) + + $cmap=@{r='red';g='green';b='blue';i='indigo';v='violet';c='cyan'} + $mmap=@{Ci='Circle';Da='Dash';di='diamond';do='dot';pl='plus';sq='square';tr='triangle'} + + $this.chart.Series[0].Marker = $mmap.$m + $this.chart.Series[0].MarkerColor = $cmap.$c + $this.chart.Series[0].MarkerLineColor = $cmap.$c + } + hidden [string]GetNextColumnName($columnName) { return $this.GetColumnName($this.GetColumnNumber($columnName)+1) } @@ -144,6 +186,10 @@ class PSPlot { $this.chart.SetSize($width, $height) } + Title($title) { + $this.chart.Title.Text = $title + } + Show() { $this.pkg.Save() $this.pkg.Dispose()