VB如何读取txt数据绘制曲线?

txt中有两列数据,类似下面的样式。想前面一列数据作为纵坐标,后面一列数据作为横坐标。坐标原点在左下角,X轴范围为0到0.1,Y轴范围为0到1000。如何编写代码啊?想用picture box或者新的窗口来输出图像。万分感谢!
235.732965 0.001992
238.594252 0.002198
241.461107 0.002423
244.334413 0.002668
247.214344 0.002934
250.101825 0.003224
252.997309 0.003539
255.901261 0.003879
258.814670 0.004249
261.738563 0.004649
264.673206 0.005081
267.619933 0.005549
270.579313 0.006054
273.552745 0.006598
276.541120 0.007185
最新回答
野稚

2024-06-05 00:13:53

Dim g As Graphics = PictureBox1.CreateGraphics()
Dim pen As New Pen(Color.Black, 1)
Dim xMin As Double = 0
Dim xMax As Double = 0.1
Dim yMin As Double = 0
Dim yMax As Double = 1000
'读取数据
Dim data() As String = IO.File.ReadAllLines("data.txt")
Dim xy(data.Length - 1, 1) As Double
For i As Integer = 0 To data.Length - 1
Dim temp() As String = data(i).Split(" ")
xy(i, 0) = CDbl(temp(0))
xy(i, 1) = CDbl(temp(1))
Next
'绘制坐标轴
g.DrawLine(pen, 0, PictureBox1.Height, 0, 0)
g.DrawLine(pen, 0, PictureBox1.Height, PictureBox1.Width, PictureBox1.Height)
'绘制数据点
Dim pointSize As Integer = 3
For i As Integer = 0 To xy.GetLength(0) - 1
Dim x As Integer = CInt((xy(i, 1) - xMin) / (xMax - xMin) * PictureBox1.Width)
Dim y As Integer = CInt((xy(i, 0) - yMin) / (yMax - yMin) * PictureBox1.Height)
g.DrawEllipse(pen, x - pointSize \ 2, PictureBox1.Height - y - pointSize \ 2, pointSize, pointSize)
Next
其中,data.txt是存储数据的文件名,PictureBox1是用来显示图像的控件,可以根据需要进行修改。
追问

谢谢你的热心回答。不过我测试了下,运行不了啊,我用的是VB6啊,你这个貌似用的不是VB6啊。我想的是单击command button,然后就可以在picture.box里头绘图。我是菜鸟,麻烦你再看看,谢谢!