2014-04-16 70 views
3

我嘗試在excel中繪製vba中一個圖中的兩個圖。一個具有從-10到10的離散x範圍,另一個是近似的「連續」高斯分佈,從步幅範圍0.1到-10從-10縮放。Excel VBA SeriesCollection兩個具有不同x值標度的系列

Dim xvalue_norm(201) As Double 
Dim NormFassung(201) As Double 
Dim c As Integer 

For i = 1 To 20 
    For j = 1 To 10 
     c = c + 1    
     xvalue_norm(c) = i - 11 + (j - 1)/10 '(-10,-9.9,-9.8,...,10) 
     NormFassung(c) = WorksheetFunction.NormDist(i - 11 + (j - 1)/10, mean_fassung, sigma_fassung, False) 
    Next j 
Next i 

Dim xvalue_hist(21) As Double 
Dim HistFassung(21) As Double 

For i = 1 To 21 
    xvalue_hist(i) = (i - 11) '(-10,-9,-8,...,10) 
    HistFassung(i) = Fassung(i)/summe_fassung 
Next i 


ActiveSheet.Shapes.AddChart.Select 
ActiveChart.ChartType = xlLine 
ActiveChart.Location Where:=xlLocationAsNewSheet  
ActiveChart.Axes(xlValue).MinimumScale = 0 
ActiveChart.Axes(xlValue).MaximumScale = 0.5 

    'Series 1 : 
    ActiveChart.SeriesCollection.NewSeries 
    ActiveChart.SeriesCollection(1).Name = "NormVert" 
    ActiveChart.SeriesCollection(1).XValues = xvalue_norm 
    ActiveChart.SeriesCollection(1).Values = NormFassung 

    'Series 2 : 
    ActiveChart.SeriesCollection.NewSeries 
    ActiveChart.SeriesCollection(2).Name = "Historie" 
    ActiveChart.SeriesCollection(2).XValues = xvalue_hist 
    ActiveChart.SeriesCollection(2).Values = HistFassung 

該圖被正確地從-10右邊x值範圍初始化爲10和第一系列繪製好,但系列2的xvalues「回顧歷史」似乎使用的範圍內(-10, - 9.9,-9.8,..., - 8)而不是離散值(-10,-9,-8,...,10)。

+0

您是否嘗試使用圖表嚮導添加不同的x軸?我不確定是否可以定義不同的XValues。 – MP24

回答

0

很抱歉,下列符號未定義,因此代碼無法編譯。

i , j, mean_fassung, sigma_fassung, summe_fassung 

難以進展。

相關問題