Question

In my project I have created a chart and I want there to be the same number of points as in my textboxes, how can i do that? this is my code

 Public Class Form1
      Dim a As Object
      Dim b As Object

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    Chart1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top
    Chart1.ChartAreas(0).AxisX.Maximum = 20
    Chart1.ChartAreas(0).AxisY.Maximum = 30
    Chart1.ChartAreas(0).AxisX.Minimum = -20
    Chart1.ChartAreas(0).AxisY.Minimum = -30
    Chart1.ChartAreas(0).AxisY.Interval = 5
    Chart1.ChartAreas(0).AxisX.Interval = 5
    Chart1.ChartAreas(0).AxisX.Crossing = 0
    Chart1.ChartAreas(0).AxisY.Crossing = 0
    Chart1.ChartAreas(0).AxisX.LineWidth = 2
    Chart1.ChartAreas(0).AxisY.LineWidth = 2
    Chart1.ChartAreas(0).AxisY.MajorGrid.LineColor = Color.Black

    a = New DataPoint(0, 0)
    a.Label = "#VALX : #VALY"
    a.MarkerStyle = MarkerStyle.Circle
    a.MarkerSize = 5
    Chart1.Series(0).Points.Add(a)
End Sub

And I want the datapoints to be like

 a =(val(textbox1.text),val(textbox2.text))
Was it helpful?

Solution

In the below example I just created a collection of textboxes and looped through them adding the x and y coordinates from the textboxes

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

    Dim Xtbs() As TextBox = {TextBox1, TextBox3, TextBox5}
    Dim Ytbs() As TextBox = {TextBox2, TextBox4, TextBox6}

    For i As Integer = 0 To Xtbs.Length - 1
        Dim x As Double = Xtbs(i).Text
        Dim y As Double = Ytbs(i).Text
        Dim pt = New DataPoint(x, y)
        Chart1.Series(0).Points.Add(pt)
    Next

End Sub

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top