9 Replies - 31183 Views - Last Post: 13 January 2011 - 05:29 AM Rate Topic: -----

#1 M-rhodes  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-September 10

Creating a line graph on VB.NET tutorial available?

Posted 10 January 2011 - 10:03 AM

Hi, are there any tutorials on DIC or other programming websites for Creating a line graph on VB.NET?

all help appreciated,

regards,

matt
Is This A Good Question/Topic? 0
  • +

Replies To: Creating a line graph on VB.NET tutorial available?

#2 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Creating a line graph on VB.NET tutorial available?

Posted 10 January 2011 - 10:32 AM

There is a chart tool where you can add your values and plot in various styles

Here's a simple example of creating a line graph with a single series containing 3 data points.

Drag a chart to your form and add this code
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Chart1.Series.Clear()
        Chart1.Titles.Add("Demo")
        'Create a new series and add data points to it.
        Dim s As New Series
        s.Name = "aline"
        'Change to a line graph.
        s.ChartType = SeriesChartType.Line
        s.Points.AddXY("1990", 27)
        s.Points.AddXY("1991", 15)
        s.Points.AddXY("1992", 17)
        'Add the series to the Chart1 control.
        Chart1.Series.Add(s)
    End Sub


You will need to add Imports System.Windows.Forms.DataVisualization.Charting

Of course you would have to iterate through your data and add points based on your information.
Was This Post Helpful? 2
  • +
  • -

#3 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: Creating a line graph on VB.NET tutorial available?

Posted 10 January 2011 - 12:51 PM

Charlie,

You should mention that the Namespace is only available in .NET Framework 4.

http://msdn.microsof...n.charting.aspx
Was This Post Helpful? 2
  • +
  • -

#4 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Creating a line graph on VB.NET tutorial available?

Posted 10 January 2011 - 01:05 PM

Ahh yes, thanks Shadar, I had completely took that for granted.
Was This Post Helpful? 0
  • +
  • -

#5 M-rhodes  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-September 10

Re: Creating a line graph on VB.NET tutorial available?

Posted 11 January 2011 - 09:05 AM

"A chart element with the name 'aline' already exists in the 'SeriesCollection'" regarding this code


 Chart1.Series.Add(seriesofvalues)




any thoughts?

regards,

matt

This post has been edited by M-rhodes: 11 January 2011 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Creating a line graph on VB.NET tutorial available?

Posted 11 January 2011 - 09:12 AM

Without seeing more code, It would appear that you are either adding the points incorrectly or you are repeating the same code on a graph where this information was already plotted.

Show us what you have and how you're using it.
Was This Post Helpful? 0
  • +
  • -

#7 M-rhodes  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-September 10

Re: Creating a line graph on VB.NET tutorial available?

Posted 12 January 2011 - 10:17 AM

Hi, the problem was the latter and id solved it yesterday and forgot to reply that i had solved it.

apologies,

matt
Was This Post Helpful? 0
  • +
  • -

#8 M-rhodes  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 83
  • Joined: 24-September 10

Re: Creating a line graph on VB.NET tutorial available?

Posted 12 January 2011 - 10:44 AM

Charlie, I have thought about the iteration and placing a loop on the exterior of this code:

      s.Points.AddXY("1990", 27)  
      s.Points.AddXY("1991", 15)  

      s.Points.AddXY("1992", 17)  





The data im placing onto the form is in 2 1d arrays and iam wondering how i would be able to write them to the s.points array. I understand about placing them into the array. but its how would i be able to create an additional s.points array to add another point.

regards,

matt
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Creating a line graph on VB.NET tutorial available?

Posted 12 January 2011 - 12:20 PM

Since you are iterating the array you would only need a single addxy

Here's a simplified example based on each array index corresponding to the same index in the other array. In other words, xArray(0) corresponds to yArray(0).
        Dim xArray() As String = {"1990", "1991", "1992"}
        Dim yArray() As Integer = {27, 15, 17}


Then your points would be added with the following loop
        For idx As Integer = 0 to xArray.Count - 1 ' since both arrays should have the same qty, either's count should be fine.
            s.Points.AddXY(xArray(idx), yArray(idx))
        Next

Was This Post Helpful? 3
  • +
  • -

#10 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: Creating a line graph on VB.NET tutorial available?

Posted 13 January 2011 - 05:29 AM

Hey you Guys is there a way of creating a dynamic Chart(Bar graph maybe) that is dynamic.I have read the tutorial on this website but the charts are not dynamic
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1