gpt4 book ai didi

winforms - Powershell 3D WinForms 3D 图表

转载 作者:行者123 更新时间:2023-12-03 06:32:46 25 4
gpt4 key购买 nike

我在使图表以 3D 形式显示时遇到一些问题,这是我的代码

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
$WeekTable = @{
"Week1" = 50
"Week2" = 50
}
$WeekChart = New-Object System.Windows.Forms.DataVisualization.Charting.Chart
$WeekChart.Width = 1200
$WeekChart.Height = 768
$WeekChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea3DStyle
$WeekChartArea.Enable3D = $true
$WeekChart.ChartAreas.Add($WeekChartArea)
$WeekChart.Series.Add("Data")
$WeekChart.Series["Data"].Points.DataBindXY($WeekTable.Keys, $WeekTable.Values)
#$WeekChart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
# Display chart on form
$WeekChart.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 = "Escape Windows XP statistics"
$Form.Width = 1024
$Form.Height = 820
$Form.controls.add($WeekChart)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

图表在我的表单上显示良好,但未以 3D 形式显示。 Enable3D 属性应该是 true 吗?如果我检查脚本何时完成

最佳答案

您看到的问题是 ChartArea3DStyle 不是 ChartArea,因为它不是从 ChartArea 类继承的。但是,当您调用 $WeekChart.ChartAreas.Add($WeekChartArea) 时,您会像使用 ChartArea 一样使用它。我不知道为什么这没有引发异常,但在我看来确实应该如此。

相反,您只需创建一个 ChartArea,然后更改其 Area3DStyle property为您的 ChartArea3DStyle 实例的值。不要将 ChartArea3DStyle 对象视为 ChartArea,因为它不是一个。

$Area3DStyle = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea3DStyle;
$Area3DStyle.Enable3D = $true;
$ChartArea = $WeekChart.ChartAreas.Add('ChartArea');
$ChartArea.Area3DStyle = $WeekChartArea;

3D Windows Forms Chart Screenshot

最终的脚本如下所示:

[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
$WeekTable = @{
"Week1" = 50
"Week2" = 50
}
$WeekChart = New-Object System.Windows.Forms.DataVisualization.Charting.Chart
$WeekChart.Width = 1200
$WeekChart.Height = 768
$Area3DStyle = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea3DStyle;
$Area3DStyle.Enable3D = $true;
$ChartArea = $WeekChart.ChartAreas.Add('ChartArea');
$ChartArea.Area3DStyle = $Area3DStyle;

$ChartSeries = $WeekChart.Series.Add("Data")
$WeekChart.Series["Data"].Points.DataBindXY($WeekTable.Keys, $WeekTable.Values)
#$WeekChart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie
# Display chart on form
$WeekChart.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 = "Escape Windows XP statistics"
$Form.Width = 1024
$Form.Height = 820
$Form.controls.add($WeekChart)
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()

关于winforms - Powershell 3D WinForms 3D 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com