使用Excel数据源以vb.net形式绘制图表 [英] Charting in vb.net form using excel data source
问题描述
我有一个带有按钮&的表格。图表对象。我有一个Excel表,我正在动态填充。列C& D具有标题 EOS和单元格C1&中的计数 D1分别。数据填充开始C2& C。 D2开始直到行数可变。
I have a form in which there is a button & chart object. I have an excel sheet which I am populating dynamically. Columns C & D have headers "EOS" & "Count" in cells C1 & D1 respectively. The data filling starts C2 & D2 onwards till variable number of rows.
我想要的是,当单击按钮n窗体时,购物车区域中将显示一个简单的条形图。图表的X轴应为C2,C3,...,Cn值,Y轴应为D2,D3,...,Dn值。我从页面中获得以下代码可以满足我的需要,但是使用Access数据库作为源。
What I want is, when the button n form is clicked, a simple bar chart is displayed in the cart area. the chart should have X-axis as C2, C3, ....,Cn values and Y-axis as D2, D3, ....,Dn values. I have the following code from this page that does what I need but uses an Access db as source.
有人可以告诉我如何使用 excel工作表
作为数据源来实现它吗?
Can anyone please show me how to achieve it using excel sheet
as data source?
'~~> Code to generate the chart
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
Dim strConn As String = _
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & TextBox1.Text & _
";Persist Security Info=False;"
Dim tblFields As String = "SELECT * from Table1"
Dim conn As New OleDbConnection(strConn)
Dim oCmd As New OleDbCommand(tblFields, conn)
Dim oData As New OleDbDataAdapter(tblFields, conn)
Dim ds As New DataSet
conn.Open()
oData.Fill(ds, "Table1")
conn.Close()
Chart1.DataSource = ds.Tables("Table1")
Dim Series1 As Series = Chart1.Series("Series1")
Series1.Name = "Sales"
Chart1.Series(Series1.Name).XValueMember = "nFruits"
Chart1.Series(Series1.Name).YValueMembers = "nSales"
Chart1.Size = New System.Drawing.Size(780, 350)
End Sub
推荐答案
有很多从Excel读取的示例
There are many examples of reading from Excel
使用VB.NET读取和写入Excel文件
http://www.codeproject.com/Articles/18073/Reading-and-writing-an-Excel-file-using-VB-NET
从Visual Basic .NET中的Excel工作簿中读取数据
http://www.vb-helper.com/howto_net_read_excel.html
VB.NET Excel
< a href = http://www.dotnetperls.com/excel-vbnet rel = nofollow> http://www.dotnetperls.com/excel-vbnet
还用C#编写的用于读取Microsoft Excel文件的库('97 -2007)
http://exceldatareader.codeplex.com/
这篇关于使用Excel数据源以vb.net形式绘制图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!