我正在寻找我的问题的答案,但我尝试的所有代码都不适合我,所以我决定寻求帮助。 我是在VB.net制作图表的新手,我的老板想要结果(到昨天)所以我没有时间深入挖掘如何制作图表。
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim a As Double
Dim b As String
b = RichTextBox1.Text
a = Convert.ToDouble(b)
'Chart1.DataBindTable(b)
' Chart1.(RichTextBox1.Text)
'Chart1.Series("Series1").Points.DataBindY(RichTextBox1.Text)
'Convert.ToInt32(b, 0)
Chart1.DataSource = RichTextBox1.Text
'Chart1.Series("Series1").Points.DataBindY(RichTextBox1.Text)
'Chart1.Series("Series1").Points.AddY(b)
'Chart1.Series("Series1").YValueMembers = b
Me.Chart1.Series("Series1").Points.AddY(a)
'MsgBox(RichTextBox1.Text)
MsgBox(a)
'Me.Chart1.Series("Series1").Points.InsertY(b)
Me.Refresh()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
我想绘制一个折线图。 我有一个包含10个数字和一个按钮的列表框。我想根据这些数字制作折线图 我也尝试使用richtextbox而不是列表框,但没有运气。 我想得到附图所示的内容。
非常感谢您的帮助。 sample made in excel
答案 0 :(得分:0)
- 更新--- 将此部分替换为下面提供的代码区域
Dim x2 As Integer = 0 ' Keep a track of index
For Each i As Integer In ListBox1.Items
' create a Point with index as x and the actual value of list item as y
s.Points.AddXY(Convert.toDouble(x2), Convert.toDouble(i))
x2 = x2+1
Next
图表应该是这样的
Chart1.Series.Clear() 'Empty your chart of any previous values
Chart1.Titles.Add("My Line chart") 'Add a Title
Dim s As New Series 'Create a new series
s.Name = "My Line" 'Series name
s.ChartType = SeriesChartType.Line 'Chart type
'Most important part, the points to plot
'Points START
s.Points.AddXY(1, 2)
s.Points.AddXY(3, 4)
s.Points.AddXY(5, 9)
'Points END
'Add the series to the Chart1 control
Chart1.Series.Add(s)
我不确定你为什么使用RichTextBox1。如果您正在收集用户输入(x,y)点,那么您将需要构建您的积分。
使用TextBox
控件代替RichText
,只需使用给定的说明即可。
用这个
替换上面代码中的Points位'Assume the user is entering value/numbers separated by ","
'Use the input as both x and y
'e.g 1,2,3,...
Dim textCont As String = TextBox.Text
Dim boxValues As String() = textCont.Split(New Char() {","})
For Each item In boxValues
s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
s.Points.AddXY(Convert.toDouble(item), Convert.toDouble(item))
Next
就您提供的代码而言,此示例中没有ListBox
控件或引用。
答案 1 :(得分:0)
这是修改后的form2
公共类X_axis_chart
Private Sub X_axis_chart_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim a As Integer
ListBox1.Items.Clear()
For a = 0 To Main.ListBox2.Items.Count - 1 Step 1
ListBox1.Items.Add(Main.ListBox2.Items.Item(a).ToString)
Next
'Chart1.Series("X axis").Points.DataBindY(ListBox1.Text)
Chart1.Series("X axis").Points.AddXY("Text", ListBox1.Text)
End Sub
结束班