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")
}