- 帖子
- 6
- 主題
- 1
- 精華
- 0
- 積分
- 50
- 點名
- 0
- 作業系統
- Windows 7
- 軟體版本
- Office 2007
- 閱讀權限
- 20
- 性別
- 女
- 來自
- Taiwan
- 註冊時間
- 2015-12-10
- 最後登錄
- 2017-10-19
|
回復 5# stillfish00
S大您好:
在研究的過程中小妹又遇到了以下問題QQ,請大大們幫忙解惑 ><
1.就是說折線圖中的XValues值是連續的,也就是XValues從2012/10/16~2015/9/16是不間斷的值,但因為股市會休市的關係,交易日期是不連續的,導致XValues大於總筆數720筆。
因此indx指向日期會產生偏差。目前小妹的解決方式是將用A欄日期放到陣列(XValueOutZero)中,再用indx指向此陣列(XValueOutZero)。下面是小妹加的程式碼- Private Sub myChartClass_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
- Dim pt_x As Double, interval As Double, indx As Long
- Dim arValues, XValueOutZero
-
- XValueOutZero = Range("A2:A721").Value
- pt_x = 75 * x / ActiveWindow.Zoom
- interval = myChartClass.PlotArea.InsideWidth / UBound(myChartClass.SeriesCollection(1).XValues) '傳回此陣列之維度之最高可用註標(索引)
- indx = Application.RoundUp((pt_x - myChartClass.PlotArea.InsideLeft) / interval, 0)
- indx = Application.Min(Application.Max(1, indx), UBound(myChartClass.SeriesCollection(1).XValues))
-
- With myChartClass.SeriesCollection
- If .Count = 0 Then Exit Sub
- For i = 1 To .Count
- With .Item(i)
- .ApplyDataLabels Type:=xlDataLabelsShowNone
- .Points(indx).ApplyDataLabels Type:=xlDataLabelsShowValue
- .Points(indx).DataLabel.Format.Fill.ForeColor.RGB = RGB(255, 255, 0)
- arValues = .Values
- If i <= myTarget.Cells.Count Then myTarget.Cells(i + 1).Value = arValues(indx)
- End With
- Next
- 'arValues = .Item(1).XValues
- myTarget.Cells(1).Value = XValueOutZero(indx, 1)
- End With
- myVLine.Line.ForeColor.RGB = RGB(0, 0, 0)
- myVLine.Line.Weight = 0.25
- With myChartClass
- If .Axes(xlCategory).AxisBetweenCategories Then
- myVLine.Left = .PlotArea.InsideLeft + (indx - 0.5) * interval
- Else
- myVLine.Left = .PlotArea.InsideLeft + (indx - 1) * interval
- End If
- End With
- End Sub
複製代碼 但是這樣子又發現vline無法精準的指向正確的日期,如圖1,vline指向的日期應該是2015/5/16,但是卻顯示2015/5/19的日期:'(
2. 另外,myChartClass_MouseMove是在進入滑鼠在圖表中移動這個事件發生時所執行的程式,它需要有4個傳入值- myChartClass_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
複製代碼 ,但在滑鼠在圖表移動時並沒有執行其它程式碼,那麼 myChartClass_MouseMove 是怎麼得到這些傳入值的呢,這些傳入值又是什麼 ?
3. 最後想請問大大下面這段程式的用意是什麼 >< ?- With myChartClass
- If .Axes(xlCategory).AxisBetweenCategories Then
- myVLine.Left = .PlotArea.InsideLeft + (indx - 0.5) * interval
- Else
- myVLine.Left = .PlotArea.InsideLeft + (indx - 1) * interval
- End If
- End With
- End Sub
複製代碼 以上問題小妹百思不得其解,求助大大們,問題多又笨也請各位大大海涵:Q :Q |
|