2

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
2

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Sure. I'll add an example later
Got it working in vb.net. And the data was actually linked to a database (forgot to add that to my question). Thanks!
2

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.