Вверх ↑
Ответов: 786
Рейтинг: 168
#1: 2024-06-29 14:31:30 ЛС | профиль | цитата
Круговая диаграмма (PieChart )
Вариант 1

Add(MainForm,2953706,70,119)
{
Width=549
Height=316
Point(onClose)
link(onCreate,4794102:doString,[])
link(onClose,10162556:doConsoleTerminate,[])
}
Add(FormatStr,4794102,126,133)
{
Mask="Add-Type -AssemblyName System.Windows.Forms.DataVisualization\r\n[System.Windows.Forms.DataVisualization.Charting.Chart]::new()\r\n\r\nFunction Out-PieChart {\r\n [CmdletBinding()]\r\n param (\r\n [Parameter(ValueFromPipeline)]\r\n [psobject] $inputObject,\r\n [Parameter()]\r\n [string] $PieChartTitle,\r\n [Parameter()]\r\n [int] $ChartWidth = 800,\r\n [Parameter()]\r\n [int] $ChartHeight = 400,\r\n [Parameter()]\r\n [string[]] $NameProperty,\r\n [Parameter()]\r\n [string] $ValueProperty,\r\n [Parameter()]\r\n [switch] $Pie3D,\r\n [Parameter()]\r\n [switch] $DisplayToScreen,\r\n [Parameter()]\r\n [string] $saveImage\r\n )\r\n begin {\r\n Add-Type -AssemblyName System.Windows.Forms.DataVisualization\r\n # Frame\r\n $Chart = [System.Windows.Forms.DataVisualization.Charting.Chart]@{\r\n Width = $ChartWidth\r\n Height = $ChartHeight\r\n BackColor = 'White'\r\n BorderColor = 'Black'\r\n }\r\n # Body\r\n $null = $Chart.Titles.Add($PieChartTitle)\r\n $Chart.Titles[0].Font = 'segoeuilight,20pt'\r\n $Chart.Titles[0].Alignment = 'TopCenter'\r\n # Create Chart Area\r\n $ChartArea = [System.Windows.Forms.DataVisualization.Charting.ChartArea]::new()\r\n $ChartArea.Area3DStyle.Enable3D = $Pie3D.ToBool()\r\n $ChartArea.Area3DStyle.Inclination = 50\r\n $Chart.ChartAreas.Add($ChartArea)\r\n # Define Chart Area\r\n $null = $Chart.Series.Add('Data')\r\n $Chart.Series['Data'].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie\r\n # Chart style\r\n $Chart.Series['Data']['PieLabelStyle'] = 'Outside'\r\n $Chart.Series['Data']['PieLineColor'] = 'Black'\r\n $Chart.Series['Data']['PieDrawingStyle'] = 'Concave'\r\n\r\n $chart.Series['Data'].IsValueShownAsLabel = $true\r\n $chart.series['Data'].Label = '#PERCENT\n#VALX'\r\n # Set ArrayList\r\n $XColumn = [System.Collections.ArrayList]::new()\r\n $yColumn = [System.Collections.ArrayList]::new()\r\n }\r\n process {\r\n if (-not $valueProperty) {\r\n $numericProperties = foreach ($property in $inputObject.PSObject.Properties) {\r\n if ([Double]::TryParse($property.Value, [Ref]$null)) {\r\n $property.Name\r\n }\r\n }\r\n if (@($numericProperties).Count -eq 1) {\r\n $valueProperty = $numericProperties\r\n }\r\n else {\r\n throw 'Unable to automatically determine properties to graph'\r\n }\r\n }\r\n if (-not $LabelProperty) {\r\n if ($inputObject.PSObject.Properties.Count -eq 2) {\r\n $LabelProperty = $inputObject.Properties.Name -ne $valueProperty\r\n }\r\n elseif ($inputObject.PSObject.Properties.Item('Name')) {\r\n $LabelProperty = 'Name'\r\n }\r\n else {\r\n throw 'Cannot convert Data'\r\n }\r\n }\r\n # Bind chart columns\r\n $null = $yColumn.Add($InputObject.$valueProperty)\r\n $null = $xColumn.Add($inputObject.$LabelProperty)\r\n }\r\n end {\r\n # Add data to chart\r\n $Chart.Series['Data'].Points.DataBindXY($xColumn, $yColumn)\r\n # Save file\r\n if ($psboundparameters.ContainsKey('saveImage')) {\r\n try{\r\n if (Test-Path (Split-Path $saveImage -Parent)) {\r\n $SaveImage = $pscmdlet.GetUnresolvedProviderPathFromPSPath($saveImage)\r\n $Chart.SaveImage($saveImage, 'png')\r\n } else {\r\n throw 'Invalid path, the parent directory must exist'\r\n }\r\n } catch {\r\n throw\r\n }\r\n }\r\n # Display Chart to screen\r\n if ($DisplayToScreen.ToBool()) {\r\n $Form = [Windows.Forms.Form]@{\r\n Width = 800\r\n Height = 450\r\n AutoSize = $true\r\n FormBorderStyle = 'FixedDialog'\r\n MaximizeBox = $false\r\n MinimizeBox = $false\r\n KeyPreview = $true\r\n }\r\n $Form.controls.add($Chart)\r\n $Chart.Anchor = 'Bottom, Right, Top, Left'\r\n $Form.Add_KeyDown({\r\n if ($_.KeyCode -eq 'Escape') { $Form.Close() }\r\n })\r\n $Form.Add_Shown( {$Form.Activate()})\r\n $form.Handle | Set-Clipboard\r\n $Form.ShowDialog() | Out-Null\r\n }\r\n }\r\n}\r\n\r\n@'\r\n%1\r\n'@ | ConvertFrom-Csv -Delimiter ';' |\r\n Out-PieChart -PieChartTitle '%2' -DisplayToScreen\r\n\r\n"
link(onFString,10162556:doConsoleExec,[])
link(Str1,3128668:Text,[])
link(Str2,13553777:Text,[(139,117)(174,117)])
}
Add(WinExec,10162556,182,119)
{
FileName="powershell"
Mode=0
Action="runas"
Point(doConsoleExec)
Point(onConsoleResult)
Point(onConsoleError)
Point(doConsoleTerminate)
Point(onConsoleTerminate)
link(onConsoleTerminate,4020321:doSetText,[])
}
Add(StrList,3128668,126,77)
{
Strings=#15:Name;Population|16:Индия;1428167000|16:Китай;1411750000|13:США;334233854|19:Индонезия;274900000|18:Пакистан;241499431|17:Нигерия;226826390|18:Бразилия;220165780|19:Бангладеш;169828911|16:Россия;146447400|17:Мексика;133649565|
}
Add(ClipboardHook,4020321,238,147)
{
link(onChange,11749786:doVisible,[])
}
Add(WinTools,11749786,294,147)
{
}
Add(VisualStrings,13553777,168,77)
{
Lines=#39:Топ 10 стран с самым большим населением|
Width=228
}

Вариант 2

Add(MainForm,7880538,140,168)
{
Width=549
Height=316
Point(onClose)
link(onCreate,4794102:doString,[])
link(onClose,10162556:doConsoleTerminate,[])
}
Add(FormatStr,4794102,196,182)
{
Mask="Add-Type -AssemblyName System.Windows.Forms.DataVisualization\r\n[System.Windows.Forms.DataVisualization.Charting.Chart]::new()\r\n\r\nFunction Out-PieChart {\r\n [CmdletBinding()]\r\n param (\r\n [Parameter(ValueFromPipeline)]\r\n [psobject] $inputObject,\r\n [Parameter()]\r\n [string] $PieChartTitle,\r\n [Parameter()]\r\n [int] $ChartWidth = 800,\r\n [Parameter()]\r\n [int] $ChartHeight = 400,\r\n [Parameter()]\r\n [string[]] $NameProperty,\r\n [Parameter()]\r\n [string] $ValueProperty,\r\n [Parameter()]\r\n [switch] $Pie3D,\r\n [Parameter()]\r\n [switch] $DisplayToScreen,\r\n [Parameter()]\r\n [string] $saveImage\r\n )\r\n begin {\r\n Add-Type -AssemblyName System.Windows.Forms.DataVisualization\r\n # Frame\r\n $Chart = [System.Windows.Forms.DataVisualization.Charting.Chart]@{\r\n Width = $ChartWidth\r\n Height = $ChartHeight\r\n BackColor = 'White'\r\n BorderColor = 'Black'\r\n }\r\n # Body\r\n $null = $Chart.Titles.Add($PieChartTitle)\r\n $Chart.Titles[0].Font = 'segoeuilight,20pt'\r\n $Chart.Titles[0].Alignment = 'TopCenter'\r\n # Create Chart Area\r\n $ChartArea = [System.Windows.Forms.DataVisualization.Charting.ChartArea]::new()\r\n $ChartArea.Area3DStyle.Enable3D = $Pie3D.ToBool()\r\n $ChartArea.Area3DStyle.Inclination = 50\r\n $Chart.ChartAreas.Add($ChartArea)\r\n # Define Chart Area\r\n $null = $Chart.Series.Add('Data')\r\n $Chart.Series['Data'].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie\r\n # Chart style\r\n $Chart.Series['Data']['PieLabelStyle'] = 'Outside'\r\n $Chart.Series['Data']['PieLineColor'] = 'Black'\r\n $Chart.Series['Data']['PieDrawingStyle'] = 'Concave'\r\n\r\n $chart.Series['Data'].IsValueShownAsLabel = $true\r\n $chart.series['Data'].Label = '#PERCENT\n#VALX'\r\n # Set ArrayList\r\n $XColumn = [System.Collections.ArrayList]::new()\r\n $yColumn = [System.Collections.ArrayList]::new()\r\n }\r\n process {\r\n if (-not $valueProperty) {\r\n $numericProperties = foreach ($property in $inputObject.PSObject.Properties) {\r\n if ([Double]::TryParse($property.Value, [Ref]$null)) {\r\n $property.Name\r\n }\r\n }\r\n if (@($numericProperties).Count -eq 1) {\r\n $valueProperty = $numericProperties\r\n }\r\n else {\r\n throw 'Unable to automatically determine properties to graph'\r\n }\r\n }\r\n if (-not $LabelProperty) {\r\n if ($inputObject.PSObject.Properties.Count -eq 2) {\r\n $LabelProperty = $inputObject.Properties.Name -ne $valueProperty\r\n }\r\n elseif ($inputObject.PSObject.Properties.Item('Name')) {\r\n $LabelProperty = 'Name'\r\n }\r\n else {\r\n throw 'Cannot convert Data'\r\n }\r\n }\r\n # Bind chart columns\r\n $null = $yColumn.Add($InputObject.$valueProperty)\r\n $null = $xColumn.Add($inputObject.$LabelProperty)\r\n }\r\n end {\r\n # Add data to chart\r\n $Chart.Series['Data'].Points.DataBindXY($xColumn, $yColumn)\r\n # Save file\r\n if ($psboundparameters.ContainsKey('saveImage')) {\r\n try{\r\n if (Test-Path (Split-Path $saveImage -Parent)) {\r\n $SaveImage = $pscmdlet.GetUnresolvedProviderPathFromPSPath($saveImage)\r\n $Chart.SaveImage($saveImage, 'png')\r\n } else {\r\n throw 'Invalid path, the parent directory must exist'\r\n }\r\n } catch {\r\n throw\r\n }\r\n }\r\n # Display Chart to screen\r\n if ($DisplayToScreen.ToBool()) {\r\n $Form = [Windows.Forms.Form]@{\r\n Width = 800\r\n Height = 450\r\n AutoSize = $true\r\n FormBorderStyle = 'FixedDialog'\r\n MaximizeBox = $false\r\n MinimizeBox = $false\r\n KeyPreview = $true\r\n }\r\n $Form.controls.add($Chart)\r\n $Chart.Anchor = 'Bottom, Right, Top, Left'\r\n $Form.Add_KeyDown({\r\n if ($_.KeyCode -eq 'Escape') { $Form.Close() }\r\n })\r\n $Form.Add_Shown( {$Form.Activate()})\r\n $form.Handle | Set-Clipboard\r\n $Form.ShowDialog() | Out-Null\r\n }\r\n }\r\n}\r\n\r\n\r\n\r\n@'\r\n%1\r\n'@ | ConvertFrom-Csv -Delimiter ';' |\r\n Out-PieChart -PieChartTitle '%2' -Pie3D -saveImage .\pie_chart.png\r\n\r\n\r\n"
link(onFString,10162556:doConsoleExec,[])
link(Str1,4364501:Text,[])
link(Str2,7146705:Text,[(209,159)(258,159)])
}
Add(WinExec,10162556,252,168)
{
FileName="powershell"
Mode=0
Action="runas"
Point(doConsoleExec)
Point(onConsoleResult)
Point(onConsoleError)
Point(doConsoleTerminate)
Point(onConsoleTerminate)
link(onConsoleTerminate,10612163:doEvent1,[])
}
Add(Image,13903628,392,196)
{
Width=533
Height=277
Align=5
}
Add(PNG,14777831,343,196)
{
FileName="pie_chart.png"
Point(doBitmap)
link(onBitmap,13903628:doLoad,[])
}
Add(Hub,10612163,301,196)
{
link(onEvent1,14777831:doLoad,[])
link(onEvent2,14777831:doBitmap,[(333,209)(333,216)])
}
Add(VisualStrings,7146705,252,126)
{
Lines=#39:Топ 10 стран с самым большим населением|
Width=228
}
Add(StrList,4364501,196,119)
{
Strings=#15:Name;Population|16:Индия;1428167000|16:Китай;1411750000|13:США;334233854|19:Индонезия;274900000|18:Пакистан;241499431|17:Нигерия;226826390|18:Бразилия;220165780|19:Бангладеш;169828911|16:Россия;146447400|17:Мексика;133649565|
}


Проверено на
- Windows 10 (x64)
- Hiasm v4.05 build 186 (delphi) rev - 2407
карма: 15

1
Голосовали:sla8a