2016-11-23 2 views
2

나는 플롯 차트 개체 및 SeriesCollection.NewSeries 코드의 부분이대칭 엑셀

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 

결과의 예는 내가 원하는 것은 내가 Y의 왼쪽에있는 값이 없어도 것을, -350에서 시작하여 X 축을 가지고있다 enter image description here 다음은이 그림에서처럼 축 (음의 방향). 실제로, 플롯 된 값이 양수 (Y 축에 대한 최대 X 값과 최소 X 값 사이의 대칭) 인 경우에도 중간에 Y 축이 있기를 원합니다. 가능한지 말해 줄 수 있고 몇 가지 예를 들어 주시겠습니까?

답변

1

안녕하세요이 같은 것을 시도 할 수 :

Dim dMinValue as Double, dMaxValue as Double 

With PPSChart 
    dMinValue = application.WorksheetFunction.Min("='" & _ 
        shInfo.Name & "'!R" & RowCount - UBound(tests) - 1 _ 
        & "C" & CInt(4 * (col + 1) - 2) & ":R" & RowCount - 1 _ 
        & "C" & CInt(4 * (col + 1) - 2)) 

    dMaxValue = application.WorksheetFunction.Max("='" & _ 
        shInfo.Name & "'!R" & RowCount - UBound(tests) - 1 _ 
        & "C" & CInt(4 * (col + 1) - 2) & ":R" & RowCount - 1 _ 
        & "C" & CInt(4 * (col + 1) - 2)) 
    .... 
    .Axes(xlValue).MinimumScale = dMinValue 
    .Axes(xlValue).MaximumScale = dMaxValue 
    .... 
End With 

내 조언, 당신은 그것은이다

Dim rSerie as Range 
Set rSerie = Range("='" & _ 
         shInfo.Name & "'!R" & RowCount - UBound(tests) - 1 _ 
         & "C" & CInt(4 * (col + 1) - 2) & ":R" & RowCount - 1 _ 
         & "C" & CInt(4 * (col + 1) - 2))) 

With .... 
    dMinValue = Application.WorksheetFunction.Min(rSerie) 
    .... 
End with 
+0

쉽게 사용하기 위해 객체에 시리즈의 값을 할당해야 처음에는 차트를 만들었고 이후에는 값을 읽고 시리즈를 만들었 기 때문에 조금 어려웠습니다. 이 코드는 .Axes (xlValue) .MinimumScale = dMinValue .Axes (xlValue) .MaximumScale = dMaxValue는 계열을 만들 때가 아니라 차트를 만들 때만 작동합니다. –

0
Sub AddChartObject() 
    Dim myChtObj As ChartObject 

    Set myChtObj = ActiveSheet.ChartObjects.Add _ 
     (Left:=100, Width:=375, Top:=75, Height:=225) 
    myChtObj.Chart.SetSourceData Source:=Sheets("Sheet1").Range("A3:G14") 
    myChtObj.Chart.ChartType = xlXYScatterLines 

    ' delete random series that might be generated 
    For Each mySeries In myChtObj.Chart.SeriesCollection 
     mySeries.Delete 
    Next mySeries 

    ' add series 
    Set mySeries = myChtObj.Chart.SeriesCollection.NewSeries 
    mySeries.XValues = Array(0, 300) 
    mySeries.Values = Array(88, 65) 

    ' rescale axis after adding series 
    With myChtObj.Chart.Axes(xlCategory) ' otherwise can use ActiveSheet.ChartObjects(1).Chart.Axes(xlCategory) 
     .MinimumScale = -350 'ActiveSheet.Range("C33").Value 
     .MaximumScale = 350 'ActiveSheet.Range("D54").Value 
    End With 
End Sub 

symmetrical horizontal axis