2

問題

プログラムでチャートシートに線形スケールと対数スケールの両方のデータを入力しようとしています。何らかの理由で、Axis.ScaleType プロパティがエラーになります。

試みられた修正

charttype を xyScatter に強制しようとしました。列挙型xlLinear = xlScaleLinearxlLogarithmic = xlScaleLogarithmic. の配置はAxis.ScaleType = xlScaleLogarithmic効果がありますが、 の場合は失敗しSeriesCollection.Count = 0ます。

助言がありますか?少しグーグルで調べると、これが比較的一般的な問題であることがわかります。

Option Explicit
Private Type xySeries
    Name As String
    X As Range
    Y As Range
    Markers As XlMarkerStyle
    Axis As XlAxisGroup
    Color As XlColorIndex
    Weight As Single
End Type

Private Type xyAxis
    NumberFormat As String
    ScaleType As XlScaleType
    Minimum As Double
    Maximum As Double
End Type

'Pass this function the chartsheet name, and and array of data for the series of custom xySeries type
Private Sub ChartData(sCSName As String, asPlots() As xySeries, XAxis As xyAxis, YAxis() As xyAxis)
    Dim cs As Chart, oSeries As Series, iPlot As Integer
    Dim sPlot As String, sAlias As String, iAlias As Integer
    'Dim rgTime As Range, rgValues As Range
    
    Set cs = ThisWorkbook.Charts(sCSName)
    
    For Each oSeries In cs.SeriesCollection
        oSeries.Delete
    Next
    
    cs.PlotVisibleOnly = False
    cs.ChartType = xlXYScatterLines
    
    
    With ThisWorkbook.Sheets("LimeData")
        
        
        For iPlot = 1 To UBound(asPlots, 1)
            
            cs.SeriesCollection.NewSeries
            cs.SeriesCollection(iPlot).ChartType = xlXYScatterLines
            cs.SeriesCollection(iPlot).Name = asPlots(iPlot).Name
            cs.SeriesCollection(iPlot).XValues = asPlots(iPlot).X
            cs.SeriesCollection(iPlot).values = asPlots(iPlot).Y
            cs.SeriesCollection(iPlot).MarkerStyle = asPlots(iPlot).Markers
            cs.SeriesCollection(iPlot).AxisGroup = asPlots(iPlot).Axis
            cs.SeriesCollection(iPlot).Format.Line.Weight = asPlots(iPlot).Weight
            
        Next iPlot
        
    End With
    
    With cs
        With .Axes(xlCategory)
            .MinimumScale = RangeNominalExtreme(asPlots(1).X, 0)
            .MaximumScale = RangeNominalExtreme(asPlots(1).X, 1)
            .TickLabels.NumberFormat = XAxis.NumberFormat

'Error occurs on the next line
            .ScaleType = XAxis.ScaleType 
'Run-Time Error '-2147467259' (80004002):
'Method 'ScaleType' of 'Axis' failed

        End With
        .Axes(xlValue, xlPrimary).ScaleType = YAxis(1).ScaleType
        .Axes(xlValue, xlSecondary).ScaleType = YAxis(2).ScaleType
    End With
End Sub
4

4 に答える 4

1

チェックアウト:

SetElement(msoElementPrimaryCategoryAxisLogScale)

http://msdn.microsoft.com/en-us/library/office/ff864118.aspx

于 2013-12-16T17:32:54.860 に答える
0

プロパティのヘルプを見ると、ScaleType「値の軸にのみ適用されます」と表示されます。xlCategoryただし、軸をではなく に設定しますxlValue。あなたが持っているデータなしではチェックできませんが、これはあなたの問題に対する可能な答えかもしれません.

于 2013-03-27T23:02:24.223 に答える