本人想做的效果圖是這樣的

資料格式如下

下面這段代碼簡單畫了個圖,遠遠不夠
Chart2.ChartAreas.Clear() '清除所有繪圖區
Chart2.Legends.Clear() '清除 圖例說明
Dim newChartAreas2 As New ChartArea("Default") '新增繪圖區
Chart2.ChartAreas.Add(newChartAreas2)
Dim newLegends2 As New Legend(legendName) '新增 圖例說明
Chart2.Legends.Add(newLegends2)
Chart2.ChartAreas("Default").Position.Height = 100 '繪圖區域所占百分比
Chart2.ChartAreas("Default").Position.Width = 100
Chart2.ChartAreas("Default").AxisX.Title = "Freq(Hz)" 'X軸名稱
Chart2.ChartAreas("Default").AxisX.TitleAlignment = StringAlignment.Center 'X軸標題位置
Chart2.ChartAreas("Default").AxisY.Title = "Phase" 'Y軸名稱
Chart2.ChartAreas("Default").AxisY.TitleAlignment = StringAlignment.Center 'Y軸標題位置
Chart2.ChartAreas("Default").AxisX.Minimum = -5
Chart2.ChartAreas("Default").AxisX.Maximum = 5
Chart2.ChartAreas("Default").AxisX.LabelStyle.Format = "0.00" 'X軸 顯示格式
Chart2.ChartAreas("Default").AxisX.MajorGrid.Enabled = True
Chart2.ChartAreas("Default").AxisX.MajorGrid.Interval = 1
Chart2.ChartAreas("Default").AxisX.MajorGrid.LineColor = Color.LightGray
Chart2.ChartAreas("Default").AxisX.MinorGrid.Enabled = True '啟用 次輔助線 功能
Chart2.ChartAreas("Default").AxisX.MinorGrid.Interval = 0.2 '次輔助線 間距為10
Chart2.ChartAreas("Default").AxisX.MinorGrid.LineColor = Color.LightSlateGray '次輔助線顏色為灰色
'Chart1.ChartAreas("Default").AxisX.Interval = 1 'Y軸的 主線間距major
Chart2.ChartAreas("Default").AxisX.MajorGrid.LineColor = Color.White
'Y軸的 數值區間
Chart2.ChartAreas("Default").AxisY.Minimum = -3141
Chart2.ChartAreas("Default").AxisY.Maximum = 3141
'Y軸的 數值間隔
Chart2.ChartAreas("Default").AxisY.MinorTickMark.IntervalOffset = 0
Chart2.ChartAreas("Default").AxisY.MajorGrid.Enabled = True
Chart2.ChartAreas("Default").AxisY.MajorGrid.Interval = 1000
Chart2.ChartAreas("Default").AxisY.MajorGrid.LineColor = Color.LightGray
Chart2.ChartAreas("Default").AxisY.MinorGrid.Enabled = True '啟用 次輔助線 功能
Chart2.ChartAreas("Default").AxisY.MinorGrid.Interval = 200 '次輔助線 間距為10
Chart2.ChartAreas("Default").AxisY.MinorGrid.LineColor = Color.LightSlateGray '次輔助線顏色為灰色
Chart2.ChartAreas("Default").AxisY.Interval = 500 'Y軸的 主線間距major
Chart2.ChartAreas("Default").AxisY.MajorGrid.LineColor = Color.White
Chart2.Series.Clear() '清除所有資料集
Dim newSeries2 As New Series("Phase")
newSeries2.ChartType = SeriesChartType.Point
newSeries2.BorderWidth = 2
newSeries2.Color = Color.Green
newSeries2.XValueType = ChartValueType.Double
newSeries2.IsValueShownAsLabel = False
newSeries2.MarkerStyle = MarkerStyle.Square
Chart2.Series.Add(newSeries2)

太丑了

望大神指點,不管用Ghphics畫還是用Chart畫都可以,另一篇帖子一樣的,大神幫解決下分都歸你,用vb.net撰寫,謝謝!
本人qq 327553229
uj5u.com熱心網友回復:
哪位大神有空幫忙?uj5u.com熱心網友回復:
又開了個提問?
,把資料粘貼上來,我幫你寫一個
uj5u.com熱心網友回復:
\ by amt$ ASPACE= 100m
$ XMTR = 200.
skp Station Freq Comp Amps Resistivity Phase %Rho sPhz
\-++------++----------++---++----++---------++------++------++-----+
2 1270.0 1.0312E+04 ExHy 0.00 1.4241E+2 704.3 0.0 0.0
2 1270.0 8.2500E+03 ExHy 0.00 1.4058E+2 1099.1 0.0 0.0
2 1270.0 6.5625E+03 ExHy 0.00 1.1265E+2 383.3 0.0 0.0
2 1270.0 5.2500E+03 ExHy 0.00 1.5113E+2 424.2 0.0 0.0
2 1270.0 4.1250E+03 ExHy 0.00 2.0328E+2 517.5 0.0 0.0
2 1270.0 3.1875E+03 ExHy 0.00 1.9876E+2 514.5 0.0 0.0
2 1270.0 2.4375E+03 ExHy 0.00 4.3090E+2 522.1 0.0 0.0
2 1270.0 1.8750E+03 ExHy 0.00 2.1704E+2 470.0 0.0 0.2
2 1270.0 1.4531E+03 ExHy 0.00 1.6007E+2 448.9 0.0 0.0
2 1270.0 1.1250E+03 ExHy 0.00 1.4590E+2 219.4 0.0 0.0
2 1270.0 8.9062E+02 ExHy 0.00 1.8394E+2 233.2 0.0 0.0
2 1270.0 7.0312E+02 ExHy 0.00 3.5919E+2 211.2 0.0 0.0
2 1270.0 5.6250E+02 ExHy 0.00 4.2860E+2 325.9 0.0 0.0
2 1270.0 4.6875E+02 ExHy 0.00 4.3002E+2 327.0 0.0 0.1
2 1270.0 3.6328E+02 ExHy 0.00 4.2860E+2 253.1 0.0 0.0
2 1270.0 2.8125E+02 ExHy 0.00 5.9807E+2 224.6 0.0 0.0
2 1270.0 2.2266E+02 ExHy 0.00 5.4479E+2 146.7 0.0 0.1
2 1270.0 1.7578E+02 ExHy 0.00 6.8133E+2 171.5 0.0 0.0
2 1270.0 1.4062E+02 ExHy 0.00 1.1656E+3 47.7 0.1 0.6
2 1270.0 1.1719E+02 ExHy 0.00 9.3740E+2 80.9 0.0 0.1
2 1270.0 9.0820E+01 ExHy 0.00 7.9470E+2 148.5 0.1 0.6
2 1270.0 7.0312E+01 ExHy 0.00 5.1185E+2 127.7 0.1 1.3
2 1270.0 5.5664E+01 ExHy 0.00 5.7502E+2 87.2 1.9 19.0
2 1270.0 4.3945E+01 ExHy 0.00 7.2269E+2 45.4 2.4 23.7
2 1270.0 3.5156E+01 ExHy 0.00 7.7471E+2 130.5 1.6 15.8
2 1270.0 2.9297E+01 ExHy 0.00 5.0295E+2 203.9 2.0 20.4
2 1270.0 2.2705E+01 ExHy 0.00 4.2005E+2 188.1 3.0 29.5
2 1270.0 1.7578E+01 ExHy 0.00 9.0828E+2 310.2 2.1 21.3
2 1270.0 1.3916E+01 ExHy 0.00 1.2186E+3 407.9 2.1 21.5
2 1270.0 1.0986E+01 ExHy 0.00 1.3440E+3 423.6 2.3 23.0
2 1270.0 8.7891E+00 ExHy 0.00 9.1394E+2 298.8 5.9 58.5
2 1270.0 7.3242E+00 ExHy 0.00 8.3083E+2 222.1 7.6 76.0
2 1270.0 5.6763E+00 ExHy 0.00 9.8137E+2 184.2 17.8 178.4
2 1270.0 4.3945E+00 ExHy 0.00 1.1592E+3 10.6 28.5 285.2
2 1270.0 3.4790E+00 ExHy 0.00 1.5731E+3 -87.7 29.7 297.0
2 1270.0 5.4932E-01 ExHy 0.00 6.2362E+3 28.0 26.3 263.2
2 1270.0 4.5776E-01 ExHy 0.00 5.6543E+3 130.2 35.7 357.3
2 1270.0 1.0312E+04 EyHx 0.00 2.4440E+1 -2364.1 0.0 0.0
2 1270.0 8.2500E+03 EyHx 0.00 9.6517E+1 -2578.8 0.0 0.0
2 1270.0 6.5625E+03 EyHx 0.00 2.3618E+2 -2733.8 0.0 0.0
2 1270.0 5.2500E+03 EyHx 0.00 3.3593E+2 -2696.4 0.0 0.0
2 1270.0 4.1250E+03 EyHx 0.00 3.9982E+2 -2711.1 0.0 0.0
2 1270.0 3.1875E+03 EyHx 0.00 8.9274E+2 -2745.1 0.0 0.0
2 1270.0 2.4375E+03 EyHx 0.00 9.5237E+2 -2745.1 0.0 0.0
2 1270.0 1.8750E+03 EyHx 0.00 1.2639E+3 -2842.0 0.0 0.0
2 1270.0 1.4531E+03 EyHx 0.00 1.9696E+3 -2833.3 0.0 0.0
2 1270.0 1.1250E+03 EyHx 0.00 2.0158E+3 -2807.5 0.0 0.0
2 1270.0 8.9062E+02 EyHx 0.00 1.5403E+3 -2664.3 0.0 0.0
2 1270.0 7.0312E+02 EyHx 0.00 8.5832E+2 -2724.2 0.0 0.1
2 1270.0 5.6250E+02 EyHx 0.00 6.9440E+2 -2815.0 0.0 0.1
2 1270.0 4.6875E+02 EyHx 0.00 3.7674E+2 -2882.6 0.0 0.4
2 1270.0 3.6328E+02 EyHx 0.00 2.8212E+2 -2774.6 0.0 0.0
2 1270.0 2.8125E+02 EyHx 0.00 1.4775E+2 -2644.8 0.0 0.1
2 1270.0 2.2266E+02 EyHx 0.00 1.8605E+2 -2638.7 0.0 0.1
2 1270.0 1.7578E+02 EyHx 0.00 2.1374E+2 -2701.1 0.0 0.1
2 1270.0 1.4062E+02 EyHx 0.00 1.9119E+2 -2649.7 0.1 1.2
2 1270.0 1.1719E+02 EyHx 0.00 1.5187E+2 -2678.8 0.0 0.1
2 1270.0 9.0820E+01 EyHx 0.00 1.8415E+2 -2724.2 0.1 1.3
2 1270.0 7.0312E+01 EyHx 0.00 1.2147E+2 -2727.9 0.2 1.6
2 1270.0 5.5664E+01 EyHx 0.00 1.2649E+2 -2849.0 1.0 10.4
2 1270.0 4.3945E+01 EyHx 0.00 1.4414E+2 -2917.1 1.2 11.8
2 1270.0 3.5156E+01 EyHx 0.00 1.4014E+2 -2881.5 2.5 24.5
2 1270.0 2.9297E+01 EyHx 0.00 1.5718E+2 -2810.6 2.6 25.5
2 1270.0 2.2705E+01 EyHx 0.00 2.0845E+2 -2792.1 2.7 27.4
2 1270.0 1.7578E+01 EyHx 0.00 3.3757E+2 -2821.8 2.6 26.1
2 1270.0 1.3916E+01 EyHx 0.00 2.0576E+2 -2923.3 4.2 42.2
2 1270.0 1.0986E+01 EyHx 0.00 2.1059E+2 -3158.5 6.8 68.2
2 1270.0 8.7891E+00 EyHx 0.00 2.4349E+2 -3464.1 9.6 95.9
2 1270.0 7.3242E+00 EyHx 0.00 3.5049E+2 -3517.0 9.4 93.9
2 1270.0 5.6763E+00 EyHx 0.00 9.3596E+2 -3410.2 9.3 92.5
2 1270.0 4.3945E+00 EyHx 0.00 1.6687E+3 -3557.0 10.8 107.8
2 1270.0 3.4790E+00 EyHx 0.00 4.1593E+3 -3547.8 8.2 82.3
2 1270.0 2.7466E+00 EyHx 0.00 6.7402E+3 -3530.7 7.4 73.7
2 1270.0 2.1973E+00 EyHx 0.00 9.6408E+3 -3327.3 12.9 129.0
2 1270.0 1.8311E+00 EyHx 0.00 1.1795E+4 -3309.7 9.8 98.5
2 1270.0 1.4191E+00 EyHx 0.00 1.1283E+4 -3428.1 13.2 132.1
2 1280.0 1.0312E+04 ExHy 0.00 6.1037E+1 420.3 0.0 0.0
2 1280.0 8.2500E+03 ExHy 0.00 7.6882E+1 343.9 0.0 0.0
2 1280.0 6.5625E+03 ExHy 0.00 9.6461E+1 302.6 0.0 0.0
2 1280.0 5.2500E+03 ExHy 0.00 1.1970E+2 317.8 0.0 0.0
2 1280.0 4.1250E+03 ExHy 0.00 1.3243E+2 286.0 0.0 0.0
2 1280.0 3.1875E+03 ExHy 0.00 1.6421E+2 289.1 0.0 0.0
2 1280.0 2.4375E+03 ExHy 0.00 1.9669E+2 276.2 0.0 0.0
2 1280.0 1.8750E+03 ExHy 0.00 2.1612E+2 237.8 0.0 0.0
2 1280.0 1.4531E+03 ExHy 0.00 2.8518E+2 249.1 0.0 0.0
2 1280.0 1.1250E+03 ExHy 0.00 3.4131E+2 380.8 0.0 0.0
2 1280.0 8.9062E+02 ExHy 0.00 3.6370E+2 406.3 0.0 0.0
2 1280.0 7.0312E+02 ExHy 0.00 4.5408E+2 413.6 0.0 0.0
2 1280.0 5.6250E+02 ExHy 0.00 4.9345E+2 353.4 0.0 0.0
2 1280.0 4.6875E+02 ExHy 0.00 5.3041E+2 368.0 0.0 0.0
2 1280.0 3.6328E+02 ExHy 0.00 6.0313E+2 404.7 0.0 0.0
2 1280.0 2.8125E+02 ExHy 0.00 6.6563E+2 370.2 0.0 0.0
2 1280.0 2.2266E+02 ExHy 0.00 7.7133E+2 363.6 0.0 0.2
2 1280.0 1.7578E+02 ExHy 0.00 9.7812E+2 360.3 0.0 0.0
2 1280.0 1.4062E+02 ExHy 0.00 1.2182E+3 235.1 0.1 1.4
2 1280.0 1.1719E+02 ExHy 0.00 1.3892E+3 248.4 0.1 1.0
2 1280.0 9.0820E+01 ExHy 0.00 1.1796E+3 301.9 0.3 3.0
2 1280.0 7.0312E+01 ExHy 0.00 9.4576E+2 160.2 0.1 1.0
2 1280.0 5.5664E+01 ExHy 0.00 1.2377E+3 50.4 0.5 4.5
2 1280.0 4.3945E+01 ExHy 0.00 1.1184E+3 3.1 0.8 7.8
2 1280.0 3.5156E+01 ExHy 0.00 1.0586E+3 54.2 1.1 11.4
2 1280.0 2.9297E+01 ExHy 0.00 9.6181E+2 36.9 1.3 13.3
2 1280.0 2.2705E+01 ExHy 0.00 8.6088E+2 56.4 2.0 19.8
2 1280.0 1.7578E+01 ExHy 0.00 5.9989E+2 225.9 2.3 22.7
2 1280.0 1.3916E+01 ExHy 0.00 9.3912E+2 292.8 2.3 23.1
2 1280.0 1.0986E+01 ExHy 0.00 1.0689E+3 267.5 2.0 19.9
2 1280.0 8.7891E+00 ExHy 0.00 1.0006E+3 218.8 5.5 54.9
2 1280.0 7.3242E+00 ExHy 0.00 8.4047E+2 211.6 6.7 67.4
2 1280.0 1.0312E+04 EyHx 0.00 1.2651E+1 -2648.3 0.0 0.1
2 1280.0 8.2500E+03 EyHx 0.00 1.7409E+1 -2729.0 0.0 0.0
2 1280.0 6.5625E+03 EyHx 0.00 3.7112E+1 -2711.9 0.0 0.0
2 1280.0 5.2500E+03 EyHx 0.00 5.0113E+1 -2699.0 0.0 0.0
2 1280.0 4.1250E+03 EyHx 0.00 5.6457E+1 -2618.4 0.0 0.0
2 1280.0 3.1875E+03 EyHx 0.00 1.0107E+2 -2628.8 0.0 0.0
2 1280.0 2.4375E+03 EyHx 0.00 1.3575E+2 -2644.3 0.0 0.0
2 1280.0 1.8750E+03 EyHx 0.00 1.6170E+2 -2657.3 0.0 0.0
2 1280.0 1.4531E+03 EyHx 0.00 2.0446E+2 -2657.7 0.0 0.0
2 1280.0 1.1250E+03 EyHx 0.00 1.9763E+2 -2746.7 0.0 0.0
2 1280.0 8.9062E+02 EyHx 0.00 1.6638E+2 -2669.7 0.0 0.0
2 1280.0 7.0312E+02 EyHx 0.00 2.7161E+2 -2726.5 0.0 0.0
2 1280.0 5.6250E+02 EyHx 0.00 2.9143E+2 -2681.9 0.0 0.0
2 1280.0 4.6875E+02 EyHx 0.00 2.9143E+2 -2680.4 0.0 0.2
2 1280.0 3.6328E+02 EyHx 0.00 2.8163E+2 -2800.4 0.0 0.1
2 1280.0 2.8125E+02 EyHx 0.00 3.5519E+2 -2920.7 0.0 0.2
2 1280.0 2.2266E+02 EyHx 0.00 3.1405E+2 -3062.7 0.0 0.5
2 1280.0 1.7578E+02 EyHx 0.00 3.4253E+2 -3107.5 0.0 0.1
2 1280.0 1.4062E+02 EyHx 0.00 5.4919E+2 -3003.2 0.1 1.2
2 1280.0 1.1719E+02 EyHx 0.00 5.9471E+2 -3155.7 0.1 0.7
2 1280.0 9.0820E+01 EyHx 0.00 6.2023E+2 -3143.6 0.3 2.9
2 1280.0 7.0312E+01 EyHx 0.00 7.7402E+2 -2922.1 0.1 1.3
2 1280.0 5.5664E+01 EyHx 0.00 1.3879E+3 -2883.9 0.2 2.4
2 1280.0 4.3945E+01 EyHx 0.00 1.7697E+3 -2873.1 0.3 3.4
2 1280.0 3.5156E+01 EyHx 0.00 9.2849E+2 -2854.3 1.1 11.4
2 1280.0 2.9297E+01 EyHx 0.00 8.9497E+2 -2834.8 1.2 12.2
2 1280.0 2.2705E+01 EyHx 0.00 1.1645E+3 -2923.8 1.4 14.3
2 1280.0 1.7578E+01 EyHx 0.00 1.2748E+3 -3025.9 1.4 14.0
2 1280.0 1.3916E+01 EyHx 0.00 1.1990E+3 -2900.2 2.5 25.3
2 1280.0 1.0986E+01 EyHx 0.00 1.4085E+3 -2824.4 3.0 29.6
2 1280.0 8.7891E+00 EyHx 0.00 1.0428E+3 -2775.6 4.3 42.5
2 1280.0 7.3242E+00 EyHx 0.00 1.1105E+3 -2702.9 4.6 45.7
第二列點單元,第三列橫軸,第六七列畫圖
uj5u.com熱心網友回復:
listbox和datagridview是用來查看資料的,可以刪掉。Chart畫圖的一些細節你再看著美化一下吧,所有設定我都用的默認。Public Class Form1
Dim ds As New DataSet
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Dim strData As String = IO.File.ReadAllText("C:\data\xxx.txt", System.Text.Encoding.UTF8) '從文本檔案里讀資料
Dim strData As String = "\ by amt
$ ASPACE= 100m
$ XMTR = 200.
skp Station Freq Comp Amps Resistivity Phase %Rho sPhz
\-++------++----------++---++----++---------++------++------++-----+
2 1270.0 1.0312E+04 ExHy 0.00 1.4241E+2 704.3 0.0 0.0
2 1270.0 8.2500E+03 ExHy 0.00 1.4058E+2 1099.1 0.0 0.0
2 1280.0 7.3242E+00 EyHx 0.00 1.1105E+3 -2702.9 4.6 45.7"
'skp Station Freq Comp Amps Resistivity Phase %Rho sPhz
For Each line As String In Split(Split(strData, $"+{vbCrLf}").Last, vbCrLf)
Dim d() As String = line.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
Dim station As String = d(1)
'為每個station創建一個DataTable作為資料源,Chart控制元件作為展示
If Not ds.Tables.Contains(station) Then
Dim _chart As New DataVisualization.Charting.Chart()
With _chart '每個Chart控制元件有兩個Area
.Name = station
.Width=680
.ChartAreas.Clear()
.ChartAreas.Add("Resistivity")
.ChartAreas.Add("Phase")
.Titles.Add($"{station} - Resistivity").Alignment = ContentAlignment.TopCenter
.Titles.Add($"{station} - Phase").Alignment = ContentAlignment.TopCenter
.Titles(1).DockedToChartArea = "Phase"
End With
FlowLayoutPanel1.Controls.Add(_chart)
'格式化資料源
Dim table As DataTable = ds.Tables.Add(station)
With table.Columns
.Add("Freq", Type.GetType("System.Double"))
.Add("Comp")
.Add("Resistivity", Type.GetType("System.Double"))
.Add("Phase", Type.GetType("System.Double"))
End With
End If
ds.Tables(station).Rows.Add(d(2), d(3), d(5), d(6))
Next
'遍歷所有station,畫圖
For Each table As DataTable In ds.Tables
ListBox1.Items.Add(table.TableName)
'每個datable代表一個station,放到一個 chart里,Resistivity畫一個area,Phase畫一個area
Dim _chart As DataVisualization.Charting.Chart = CType(FlowLayoutPanel1.Controls().Item(table.TableName), DataVisualization.Charting.Chart)
_chart.Series.Add(New DataVisualization.Charting.Series("ExHy_Resistivity"))
_chart.Series.Add(New DataVisualization.Charting.Series("EyHx_Resistivity"))
_chart.Series.Add(New DataVisualization.Charting.Series("ExHy_Phase"))
_chart.Series.Add(New DataVisualization.Charting.Series("EyHx_Phase"))
For Each s As DataVisualization.Charting.Series In _chart.Series
s.ChartType = DataVisualization.Charting.SeriesChartType.Line
Next
'通過Comp列篩選所在area, 系結Freq到X軸,Resistivity和Phase到Y軸
With _chart.Series(0)
.ChartArea = "Resistivity"
.XValueMember = "Freq"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "ExHy").
Select(Function(r) r), "Freq", "Resistivity", Nothing)
End With
With _chart.Series(1)
.ChartArea = "Resistivity"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "EyHx").
Select(Function(r) r), "Freq", "Resistivity", Nothing)
End With
With _chart.Series(2)
.ChartArea = "Phase"
.XValueMember = "Freq"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "ExHy").
Select(Function(r) r), "Freq", "Phase", Nothing)
End With
With _chart.Series(3)
.ChartArea = "Phase"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "EyHx").
Select(Function(r) r), "Freq", "Phase", Nothing)
End With
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
DataGridView1.DataSource = ds.Tables(ListBox1.SelectedItem)
End Sub
End Class
uj5u.com熱心網友回復:
好的謝了,有空我除錯看下,看哪里需要再完善的uj5u.com熱心網友回復:
直接用陣列做資料源行不行呢,這個data那個什么資料源好難看懂,圖的自適應范圍沒看到有定義?坐標軸都要取對數,因為資料間隔越來越大uj5u.com熱心網友回復:
DataTable是一個資料表物件,跟excel的作業表一樣,Column是欄位,Row是一條資料記錄。陣列應該可以,沒測過,靈活性肯定比DataTable要差一大截。Array可以用For Each添加到DataTable里。
ds.Tables(station).Rows.Add(d(2), d(3), d(5), d(6))
或者
ds.Tables(station).Rows.Add({d(2), d(3), d(5), d(6)})
間隔越來越大的話,你的Y軸就不能是Resistivity和Phase了,資料源里應該添加的Y值是Math.Log(d(5))和Math.Log(d(6)),Math.Log=ln,以e為底。Math.Log10以10為底。
Chart是自適應的,會盡量所有資料并且最大,縮放可以給Xaxis添加滾動條。
uj5u.com熱心網友回復:
是,麻煩給弄一個水平 垂直的滾動條uj5u.com熱心網友回復:
https://www.baidu.com/s?wd=.net+chart+scrollbar&rsv_spt=1&rsv_iqid=0xc84a3c8f0000341f&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&rqlang=&tn=baiduhome_pg&ch=&rsv_enter=1&inputT=4951uj5u.com熱心網友回復:
.Titles.Add($"{station} - Resistivity").Alignment = ContentAlignment.TopCenter.Titles.Add($"{station} - Phase").Alignment = ContentAlignment.TopCenter
我除錯時提示三處 $ 無效,為啥呢 ,去掉該字符后運行打開資料提示陣列越界
uj5u.com熱心網友回復:
更新到2015或者2017吧,這是2015開始有的特性,字串插值,將變數直接寫進字串,算是語法糖,和老版本里的format差不多。Sub Main()
Dim a As String = "aaa"
Dim b As String = "bbb"
Dim c As String = "ccc"
Console.WriteLine(a + "-" + b + "-" + c)
Console.WriteLine(String.Format("{0}-{1}-{2}", a, b, c))
Console.WriteLine(String.Format("{0}-{1}-{2}", {a, b, c}))
Console.WriteLine($"{a}-{b}-{c}")
'都等于aaa-bbb-ccc
Console.Read()
End Sub
.Titles.Add($"{station} - Resistivity").Alignment = ContentAlignment.TopCenter
.Titles.Add($"{station} - Phase").Alignment = ContentAlignment.TopCenter
'等效
.Titles.Add(station & " - Resistivity").Alignment = ContentAlignment.TopCenter
.Titles.Add(station & " - Phase").Alignment = ContentAlignment.TopCenter
uj5u.com熱心網友回復:
好的謝謝了,你寫的程式很好,我結帖了,您加我個qq好向您學習,謝謝 327553229uj5u.com熱心網友回復:
Split(Split(strData, $"+{vbCrLf}").Last, vbCrLf) 等效于什么呢uj5u.com熱心網友回復:
Imports System.IOImports System.Windows.Forms.DataVisualization.Charting
Imports System.Math
Public Class Form1
Dim ds As New DataSet
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
ofd.Title = "打開"
ofd.Filter = "amt資料(*.avg)|*.avg"
ofd.Multiselect = False
If ofd.ShowDialog() = DialogResult.OK Then
Dim avgFile As String = ofd.FileName
Dim sr As New StreamReader(ofd.FileName)
Dim strData As String = sr.ReadToEnd 'Dim strData As String = IO.File.ReadAllText("C:\data\xxx.txt", System.Text.Encoding.UTF8) '從文本檔案里讀資料
For Each line As String In Split(Split(strData, vbCrLf).Last, vbCrLf) 'Split(Split(strData, $"+{vbCrLf}").Last, vbCrLf)
Dim d() As String = line.Split({" "}, StringSplitOptions.RemoveEmptyEntries)
Dim station As String = d(1)
'為每個station創建一個DataTable作為資料源,Chart控制元件作為展示
If Not ds.Tables.Contains(station) Then
Dim _chart As New DataVisualization.Charting.Chart()
With _chart '每個Chart控制元件有兩個Area
.Name = station
.Width = 680
.ChartAreas.Clear()
.ChartAreas.Add("Resistivity")
.ChartAreas.Add("Phase")
.Titles.Add(station & " - Resistivity").Alignment = ContentAlignment.TopCenter '''.Titles.Add($"{station} - Resistivity").Alignment = ContentAlignment.TopCenter
.Titles.Add(station & " - Phase").Alignment = ContentAlignment.TopCenter ''''.Titles.Add($"{station} - Phase").Alignment = ContentAlignment.TopCenter
.Titles(1).DockedToChartArea = "Phase"
End With
FlowLayoutPanel1.Controls.Add(_chart)
'格式化資料源
Dim table As DataTable = ds.Tables.Add(station)
With table.Columns
.Add("Freq", Type.GetType("System.Double"))
.Add("Comp")
.Add("Resistivity", Type.GetType("System.Double"))
.Add("Phase", Type.GetType("System.Double"))
End With
End If
ds.Tables(station).Rows.Add(d(2), d(3), d(5), d(6))
Next
'遍歷所有station,畫圖
For Each table As DataTable In ds.Tables
ListBox1.Items.Add(table.TableName)
'每個datable代表一個station,放到一個 chart里,Resistivity畫一個area,Phase畫一個area
Dim _chart As DataVisualization.Charting.Chart = CType(FlowLayoutPanel1.Controls().Item(table.TableName), DataVisualization.Charting.Chart)
_chart.Series.Add(New DataVisualization.Charting.Series("ExHy_Resistivity"))
_chart.Series.Add(New DataVisualization.Charting.Series("EyHx_Resistivity"))
_chart.Series.Add(New DataVisualization.Charting.Series("ExHy_Phase"))
_chart.Series.Add(New DataVisualization.Charting.Series("EyHx_Phase"))
For Each s As DataVisualization.Charting.Series In _chart.Series
s.ChartType = DataVisualization.Charting.SeriesChartType.Line
Next
'通過Comp列篩選所在area, 系結Freq到X軸,Resistivity和Phase到Y軸
With _chart.Series(0)
.ChartArea = "Resistivity"
.XValueMember = "Freq"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "ExHy").
Select(Function(r) r), "Freq", "Resistivity", Nothing)
End With
With _chart.Series(1)
.ChartArea = "Resistivity"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "EyHx").
Select(Function(r) r), "Freq", "Resistivity", Nothing)
End With
With _chart.Series(2)
.ChartArea = "Phase"
.XValueMember = "Freq"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "ExHy").
Select(Function(r) r), "Freq", "Phase", Nothing)
End With
With _chart.Series(3)
.ChartArea = "Phase"
.Points.DataBind(
table.Rows.Cast(Of DataRow).
Where(Function(r) r("Comp") = "EyHx").
Select(Function(r) r), "Freq", "Phase", Nothing)
End With
Next
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
DataGridView1.DataSource = ds.Tables(ListBox1.SelectedItem)
End Sub
End Class
運行沒有問題,打開資料提示“索引超出陣列界限”,這是哪里的問題啊
uj5u.com熱心網友回復:
具體是哪一行?DEBUG一下,看一下出錯的物件是誰,一共有幾個元素,請求的是第幾個元素。uj5u.com熱心網友回復:
注釋掉所有On Error Resume Next陳述句,在VB IDE中運行,出錯后點擊除錯,游標會停在出錯的那條陳述句處,
或者
事先在懷疑可能有邏輯錯誤的陳述句處設定斷點,運行經過斷點時中斷,
此時可以在立即視窗中使用
?變數名
或
?函式名(函式引數)
或
程序名(引數)
輔助除錯。
uj5u.com熱心網友回復:

出錯在這里
uj5u.com熱心網友回復:
用陣列操作感徑訓清晰明了點,哪位大神幫寫個陣列操作的代碼,謝了uj5u.com熱心網友回復:
你的文本里有空行,讀到空行應該跳過此行的處理。在出錯的這行代碼上面加一句
if b.length=1 then continue for
uj5u.com熱心網友回復:
運行通過,但是沒出圖,沒反應,我傾向于陣列的代碼,這個我看起來好吃力,也不好修改uj5u.com熱心網友回復:
station這個陣列有問題,station串列沒東西加進來uj5u.com熱心網友回復:
運行還是有問題,沒看懂代碼轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/52858.html
標籤:資源
上一篇:VB如何更改檔案夾的圖示?
