0
我试图用.NET 4内置图表控件生成折线图。 我想要角度为和的X轴标签我想让我的图表具有特定的大小。.NET图表控件在指定图表大小时忽略LabelAutoFitStyle
如果指定图表的宽度/高度,则将忽略LabelAutoFitStyle。我也尝试在标签上使用.Angle属性等,并且只有在我没有指定图表的高度&时才起作用。
但是,如果我没有指定图表的宽度&高度,则数据将全部挤入非常小的图表中。
有没有办法使用LabelAutoFitStyle 和确保图表的尺寸较大,最好是特定的尺寸。
我试过使用$ chart.MinimumSize和$ chart.Size,但它们似乎没有影响图表输出。
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")
ForEach ($url in $urlList)
{
$chart = New-Object System.Windows.Forms.DataVisualization.Charting.Chart
#$chart.Width = 1024
#$chart.Height = 690
$chart.BackColor = [System.Drawing.Color]::White
$chart.Titles.Add("$url load time (ms)")
$chart.Titles[0].Alignment ="topLeft"
$chart.AutoSize = $true
$chartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$chartArea.name = "ChartArea1"
$chartArea.AxisY.Title = "Load Time (ms)"
$chartArea.AxisX.Title = "Time"
$chartArea.AxisX.IsLabelAutoFit = $true
$chartArea.AxisX.LabelAutoFitStyle = [System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles]::LabelsAngleStep90
$chartArea.Axisx.LabelStyle.Enabled = $true
$chart.ChartAreas.Add($chartArea)
$colorIndex = 0
ForEach ($pac in $pacList)
{
$chart.Series.Add($pac)
$chart.Series[$pac].ChartType = "Line"
$chart.Series[$pac].BorderWidth = $borderWidth
$chart.Series[$pac].IsVisibleInLegend = $true
$chart.Series[$pac].ChartArea = "ChartArea1"
$chart.Series[$pac].Color = $colorList[$colorindex]
$colorindex++
}
$urlData = $data | Where-Object { $_.URL -eq $url }
ForEach ($row in $urlData)
{
$chart.Series[$row.'PAC FILE'].Points.AddXY($row.TIME, $row.'Page Load Time 2 (ms)')
}
$chartFilename = (Join-Path -Path $PSScriptRoot -ChildPath (Fix-Filename $url)) + ".png"
$chart.SaveImage($chartFilename,"png")
}