2
我已經使用圖表對象和SeriesCollection.NewSeries 代碼的部分是這樣的朝着VBA系列Y軸對稱的Excel
Private Function AddSeriesAndFormats(PPSChart As Chart, shInfo As Worksheet, tests() As PPS_Test, RowCount As Integer, col As Integer, smoothLine As Boolean, lineStyle As String, transparency As Integer, lineWidth As Single, ByRef position As Integer) As Series
Dim mySeries As Series
Set mySeries = PPSChart.SeriesCollection.NewSeries
With mySeries
.Name = tests(0).GetString()
.XValues = "='" & shInfo.Name & "'!R" & RowCount - UBound(tests) - 1 & "C" & CInt(4 * (col + 1) - 2) & ":R" & RowCount - 1 & "C" & CInt(4 * (col + 1) - 2)
.Values = "='" & shInfo.Name & "'!R" & RowCount - UBound(tests) - 1 & "C" & CInt(4 * (col + 1) - 1) & ":R" & RowCount - 1 & "C" & CInt(4 * (col + 1) - 1)
.Smooth = smoothLine
.Format.line.Weight = lineWidth
.Format.line.DashStyle = GetLineStyle(lineStyle)
.Format.line.transparency = CSng(transparency/100)
.MarkerStyle = SetMarkerStyle(position)
.MarkerSize = 9
.MarkerForegroundColorIndex = xlColorIndexNone
End With
Set AddSeriesAndFormats = mySeries
End Function
和PPSChart被這樣
創建情節做了一些重複Private Function AddChartAndFormatting(chartName As String, chartTitle As String, integralBuffer As Integer, algoPropertyName As String) As Chart
Dim PPSChart As Chart, mySeries As Series
Set PPSChart = Charts.Add
With PPSChart
.Name = chartName
.HasTitle = True
.chartTitle.Characters.Text = chartTitle
.ChartType = xlXYScatterLines
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).HasTitle = True
If algoPropertyName <> "" Then 'case for Generic PPS plots
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = algoPropertyName
Else
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "PL/PR max(avg_" & integralBuffer & "ms) [mbar]" 'case for the bumper obsolate algorithm
End If
.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Bumper Position [mm]"
End With
' delete random series that might be generated
For Each mySeries In PPSChart.SeriesCollection
mySeries.Delete
Next mySeries
Set AddChartAndFormatting = PPSChart
End Function
結果的一個例子是像在下面 我想是有從-350啓動X軸,即使我沒有在Y的左邊值這個畫面軸(在負側)。實際上,我想要的是中間的Y軸,即使繪圖值是正值(最大X值和最小X值朝向Y軸之間的對稱性)。 你能告訴我,如果有可能,給我一些例子?
這是一個有點困難,因爲首先我創建圖表,然後閱讀值並創建系列。此代碼:.Axes(xlValue).MinimumScale = dMinValue .Axes(xlValue).MaximumScale = dMaxValue僅在創建圖表時生效,而不在創建系列時生效。 –