我用mschart控件统计显示数据库里的数据,我只想要显示排在前面的5条数据,应该怎样设置才可以实现.
Private Sub Form_Load()
InitializeDataPath
Adodc1.ConnectionString = AdodcPath
Adodc1.RecordSource = "select * from statistics order by 被借次数 desc"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
Exit Sub
End If
With MSChart1
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 100
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 10
.ShowLegend = False
.Enabled = False
End With
Set MSChart1.DataSource = Adodc1
MSChart1.Refresh
MSChart1.ColumnCount = 1
If Adodc1.Recordset.RecordCount < 5 Then
MSChart1.RowCount = Adodc1.Recordset.RecordCount
For i = 1 To Adodc1.Recordset.RecordCount
MSChart1.Row = i
MSChart1.RowLabel = Adodc1.Recordset.Fields("图书名称")
Next
Adodc1.Refresh
MSChart1.Refresh
Else
MSChart1.RowCount = 5
For i = 1 To 5
MSChart1.Row = i
MSChart1.RowLabel = Adodc1.Recordset.Fields("图书名称")
Next
Adodc1.Refresh
MSChart1.Refresh
Exit Sub
End If
End Sub
上面的这段代码不管数据库里有多少条记录都全部被显示出来了,请好心人帮我看看,应该怎样改.谢谢!