Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell组值Winforms图表_Winforms_Powershell_Charts_Mschart_Powershell Ise - Fatal编程技术网

Powershell组值Winforms图表

Powershell组值Winforms图表,winforms,powershell,charts,mschart,powershell-ise,Winforms,Powershell,Charts,Mschart,Powershell Ise,我有点问题。 我正在努力实现这样的目标: 页面上的第一个图表。 我这里有我的密码 ### Load assemblies [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization") $Servers = Get-XAWorkerGroup -Worker

我有点问题。 我正在努力实现这样的目标: 页面上的第一个图表。 我这里有我的密码

### Load assemblies
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

$Servers = Get-XAWorkerGroup -WorkerGroupName Agresso | select servernames -ExpandProperty servernames
$SessionTable = @()
foreach ($Server in $Servers) {
    $ActiveSessions = (Get-XASession -ServerName $Server | ?{$_.State -eq "Active"}).Count
    $DisconnectedSessions = (Get-XASession -ServerName $Server | ?{$_.State -eq "Disconnected"}).Count
    $ListeningSessions = (Get-XASession -ServerName $Server | ?{$_.State -eq "Listening"}).Count
    $LoopArray = "$Server,$ActiveSessions,$DisconnectedSessions,$ListeningSessions"
    $SessionTable += $LoopArray
}

### CREATE CHART
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart 
$Chart.Width = 1600
$Chart.Height = 400
$Chart.Left = 10 
$Chart.Top = 10

# create a chartarea to draw on and add to chart 
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea 
$Chart.ChartAreas.Add($ChartArea) 
foreach ($server in $SessionTable) {
    $Splitted = $Server.Split(",")
    $Name = $Splitted[0]
    $Active = $Splitted[1]
    $Disconnected = $Splitted[2]
    $Listening = $Splitted[3]
    [void]$Chart.Series.Add($Name)
    $dp1 = new-object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Active)
    $dp2 = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Disconnected)
    $dp3 = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Listening)
    $dp1.Color = "Blue"
    $dp2.Color = "Red"
    $dp3.Color = "Orange"
    $dp1.AxisLabel = $Name + " Active"
    $dp2.AxisLabel = $Name + " Disconnected"
    $dp3.AxisLabel = $Name + " Listening"
    $Chart.Series[$Name].Points.Add($dp1)
    $Chart.Series[$Name].Points.Add($dp2)
    $Chart.Series[$Name].Points.Add($dp3)
    $ChartArea.AxisX.LabelStyle.Angle = "-90"
    $ChartArea.AxisX.LabelStyle.Interval = "1"
}
$title = new-object System.Windows.Forms.DataVisualization.Charting.Title 
$Chart.Titles.Add( $title ) 
$Chart.Titles[0].Text = "Testing"
$Chart.Titles[0].Font = New-Object System.Drawing.Font("arial",20,[System.Drawing.FontStyle]::Bold)
### Show on form
$Chart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor 
                [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left 
$Form = New-Object Windows.Forms.Form
$Form.Text = "Testing form"
$Form.Width = 1400
$Form.Height = 820
$Form.controls.add($Chart)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
但是我的输出是这样的

我希望输出与我在顶部链接的一样,因此在我的情况下: Servername具有3个不同会话的组合值。 例如,值为6、7、0的Server1
希望我能明确自己想要实现的目标!:D

我想,你需要使用它来让它工作。下面是代码的外观

### Load assemblies
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

$SessionTable = @()
$SessionTable = Get-Content C:\Users\hemanth.damecharla\Desktop\serverdetails.txt

### CREATE CHART
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart 
$Chart.Width = 1024
$Chart.Height = 768
$Chart.Left = 10 
$Chart.Top = 10

# create a chartarea to draw on and add to chart 
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea 
$Chart.ChartAreas.Add($ChartArea) 
$seriesnames = @() #need to get all the series name to use with AlignDataPointsByAxisLabel
foreach ($server in $SessionTable) {
    $Splitted = $Server.Split(",")
    $Name = $Splitted[0]
    $Active = [double]($Splitted[1])
    $Disconnected = [double]($Splitted[2])
    $Listening = [double]($Splitted[3])
    [void]$Chart.Series.Add($Name)
    $dp1 = new-object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Active)
    $dp2 = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Disconnected)
    $dp3 = New-Object System.Windows.Forms.DataVisualization.Charting.DataPoint(0,$Listening)
    $dp1.Color = "Blue"
    $dp2.Color = "Red"
    $dp3.Color = "Orange"
    $dp1.AxisLabel = $Name + " Active"
    $dp2.AxisLabel = $Name + " Disconnected"
    $dp3.AxisLabel = $Name + " Listening"
    $Chart.Series[$Name].Points.Add($dp1)
    $Chart.Series[$Name].Points.Add($dp2)
    $Chart.Series[$Name].Points.Add($dp3)
    $ChartArea.AxisX.LabelStyle.Angle = "-90"
    $ChartArea.AxisX.LabelStyle.Interval = "1"

    $seriesnames += $Name #collect each series name
}
$seriesnames = $seriesnames -join ','

$title = new-object System.Windows.Forms.DataVisualization.Charting.Title 
$Chart.Titles.Add( $title ) 
$Chart.Titles[0].Text = "Testing"
$Chart.Titles[0].Font = New-Object System.Drawing.Font("arial",20,[System.Drawing.FontStyle]::Bold)

### Show on form
$Chart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor 
                [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left 
$Chart.AlignDataPointsByAxisLabel($seriesnames) #call the method
$Form = New-Object Windows.Forms.Form
$Form.Text = "Testing form"
$Form.Width = 1400
$Form.Height = 820
$Form.controls.add($Chart)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

当我使用你的代码时,我的结果是这样的:我唯一改变的是我的服务器输入,就像以前一样:)我知道这有点晚了。但是,是的,你展示的图片就是它的结果。我尝试了几种不同的方法,但却找不出一种方法来满足你的需求。另外,关于您在文章中链接到的代码项目示例,以及您在该文章中引用的图形。该图适用于四个不同系列,而不是单个系列的数据点。我想这可能是因为这个系列的构造方式。