我正在拔出我的头发试图解析数据或编辑成msgraph系列集合。
我得到error 438 - object does not support this property or method
。
我可以操纵对象具有的其他属性,例如ChartTitle.Font.Size,但不能处理seriescollection。
Intellisencing与这个对象不起作用,导致我认为我没有设置特定的引用。
代码的部分如下 主例程获取对象:
strReportName = "Security Selection"
strChartName = "MACD_Chart"
DoCmd.OpenReport strReportName, acViewDesign
Set rptMACD = Reports(strReportName)
Set chartMACD = rptMACD(strChartName)
构建数据记录集,然后将所有数据记录集传递到子例程:
Call UpdateChart(chartMACD, rstMACD)
Public Sub UpdateChart(chartPlot As Object, rstChart As ADODB.Recordset)
'FUNCTION:
' a chart object is passed into the routine,
' source data is update to the recordset being passed in.
Dim lngType As Long
Dim i, j, iFieldCount As Integer
Dim rst As Recordset
Dim arXValues() As Date
Dim arValues() As Double
Dim strChartName, strYAxis, strXAxis As String
Dim ChrtCollection As ChartObjects
Dim colmCount As Integer
chartPlot.RowSourceType = "Table/Query"
'get number of columns in chart table/Query
iFieldCount = rstChart.Fields.Count
With chartPlot
'change chart data to arrays of data from recordset
.Activate
j = 0
rstChart.MoveFirst
Do While Not rstChart.EOF
j = j + 1
ReDim Preserve arXValues(1 To j)
arXValues(j) = rstChart.Fields("Date").Value
rstChart.MoveNext
Loop
For i = 1 To iFieldCount - 1 'Date is first field
j = 0
rstChart.MoveFirst
Do While Not rstChart.EOF 'get next array of data
j = j + 1
ReDim Preserve arValues(1 To j)
arValues(j) = rstChart.Fields(i + 1).Value
rstChart.MoveNext
Loop
.SeriesCollection(i).Name = rstChart.Fields(i + 1).Name
.SeriesCollection(1).XValues = arXValues
.SeriesCollection(i).Values = arValues
Next i
end sub
我尝试了很多东西,现在我完全糊涂了。我也一直试图解析记录集(这是我的偏好),但我现在会采取任何措施。
答案 0 :(得分:0)
继续之前:我建议将Chart的Rowsource
属性设置为一个返回所需数据然后Requery
图表的查询。这比以下更容易 WAY 。
您收到Error 438
因为Name, XValues, Values
不是Series
对象的属性。 MSDN Info
话虽如此,这里是你的方法,并采取这样做的一些建议。 SeriesCollection
不包含与MSGraph点相关联的值,就像在Excel中一样。您需要编辑DataSheet中的数据,这非常挑剔。必须包含对Microsoft Graph Library的引用。经测试可以使用我的数据库。 Microsoft Graph MSDN info
<强> DAO 强>
Public Sub testing()
Dim rstChart As Recordset
Dim seri As Object, fld As Field
Dim app As Graph.Chart
chartPlot.SetFocus
Set app = chartPlot.Object
Set rstChart = CurrentDb.OpenRecordset("SELECT DateTime, ASIMeasured FROM Surv_ASI WHERE CycleID = 2 ORDER BY DateTime")
app.Application.DataSheet.Range("00:AA1000").Clear
With rstChart
For Each fld In .Fields
app.Application.DataSheet.Range("a1:AA1").Cells(0, fld.OrdinalPosition) = fld.Name
Next
Do While Not .EOF
For Each fld In .Fields
app.Application.DataSheet.Range("a2:AA1000").Cells(.AbsolutePosition, fld.OrdinalPosition).Value = fld
Next
.MoveNext
Loop
End With
app.Refresh
End Sub
ADO (假设rstChart
已经是有效的ADODB.Recordset)
Public Sub testing()
Dim app As Graph.Chart, i As Integer
chartPlot.SetFocus
Set app = chartPlot.Object
app.Application.DataSheet.Range("00:AA1000").Clear
With rstChart
.MoveFirst 'Since I don't know where it was left off before this procedure.
For i = 0 To .Fields.Count - 1
app.Application.DataSheet.Range("a1:AA1").Cells(0, i) = .Fields(i).Name
Next
Do While Not .EOF
For i = 0 To .Fields.Count - 1
app.Application.DataSheet.Range("a2:AA1000").Cells(.AbsolutePosition, i).Value = .Fields(i)
Next
.MoveNext
Loop
End With
app.Refresh
End Sub
关于我的变化的一些注释:
1.我更喜欢让我的With
指向Recordset循环,而不是正在操作的对象,特别是因为在你的程序中对Recordset的属性进行了更多的调用。
2.您无需指定Next
适用的变量(Next i
)。只需放Next
。
3.如果有帮助,请选择我的答案:)