dtTest.Columns.Add("TestName", GetType(String))
dtTest.Columns.Add("Score", GetType(Integer))
Dim cn As New OleDbConnection(connectionString)
cn.Open()
Dim cmd As New OleDbCommand("SELECT * From ScoreDB WHERE StudentName='" & SelectStudent.Text & "'", cn)
cmd.ExecuteNonQuery()
Dim reader As OleDbDataReader = cmd.ExecuteReader()
While (reader.Read())
Dim TestName As String = Convert.ToString(reader("TestName"))
Dim TestScore As String = Convert.ToString(reader("ScorePercentage"))
GraphValues.Add(TestName, TestScore)
End While
Dim point As KeyValuePair(Of String, Integer)
For Each point In GraphValues
dtTest.Rows.Add(point.Key)
dtTest.Rows.Add(point.Value)
MsgBox(point.Key)
Next
With Chart1.ChartAreas(0)
.AxisX.Minimum = 0
.AxisX.Maximum = 10
.AxisY.Minimum = 0
.AxisY.Maximum = 100
.AxisY.Interval = 10
.AxisX.Title = "Test"
.AxisY.Title = "Score Percentage"
End With
cn.Close()
End Sub
我已经创建了一个表格,应该将得分和测试名称输出到vb.net的柱形图中,它会成功加载数据库中的所有数据,但是无法将其写入图表,最终就像这个
任何帮助都会受到赞赏,因为我现在正在努力解决这个问题,并搜索了MSDN等各种资源。
答案 0 :(得分:0)
没有任何东西告诉图表将数据表GraphValues
映射到图表。尝试类似下面的内容。你可以稍微修改一下代码
Chart1.DataSource = GraphValues
Chart1.Series(0).XValueMember = "TestName"
Chart1.Series(0).YValueMembers = "Score"
'Data bind to the selected data source
Chart1.DataBind()
http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx