Henry Taylor
Henry Taylor

Reputation: 91

Graph on VB.NET/Java

How can I create a line graph in Java OR VB.NET with the following data?

Sales Rep       # of Sales      Date
Anthony         15              August 1
Anthony         17              August 2
Mark            27              August 1
David           27              August 1
Mark            30              August 2
David           14              August 2

Upvotes: 2

Views: 1301

Answers (2)

user3032129
user3032129

Reputation: 31

There's an open source function at www.ezVB.net.

The advantages are that

1) It takes only one line to implement, e.g.

ezDrawGraph({{0.5, 1, 3.14}, {1.2, 3, 4}}).Save("testgraph.png", Imaging.ImageFormat.Png)

2) The function can be copied directly into your code. No libraries needed.

3) It accepts either one 1D array, a set of two 1D arrays or one 2D array.

The drawdown is that the design is very basic.

(P.S. I am affiliated with ezVB.net)

Upvotes: 2

sloth
sloth

Reputation: 101142

In VB.Net, put your data into a DataTable and bind it to a Chart control

Tutorials on how to bind a DataTable to a Chart are here and here.

Also, there a some open-source chart controls like this and this.

Edit:

Here's a simple example to show you how the Chart works:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim table = New DataTable()
    table.Columns.Add("Sales Rep", GetType(String))
    table.Columns.Add("# of Sales", GetType(Integer))
    table.Columns.Add("Date", GetType(Date))

    table.Rows.Add("Anthony", 15, "2012 August 1")
    table.Rows.Add("Mark", 27, "2012 August 1")
    table.Rows.Add("David", 27, "2012 August 1")

    table.Rows.Add("Anthony", 17, "2012 August 2")
    table.Rows.Add("Mark", 30, "2012  August 2")
    table.Rows.Add("David", 14, "2012 August 2")

    Chart1.Series.RemoveAt(0)
    Chart1.DataBindCrossTable(table.DefaultView, "Sales Rep", "Date", "# of Sales", "")

    For Each s In Chart1.Series
        s.ChartType = SeriesChartType.Line
    Next
End Sub

enter image description here


Using Java, have a look into JFreeChart, which can also render different kinds of charts (and there a probably a lot of other Java controls/libs for displaying charts).

enter image description here

Upvotes: 4

Related Questions