Hi All, I hope someone can offer some help / advice.

I need to plot a fairly simple line chart/graph, using some data generated previously from another Java program (run from the console) that is output to a text file.

I'm really struggling trying to produce a viewable line chart/graph in Java.

It basically needs an x axis and a y axis, and will have various pairs of points to be plotted on these.

The only requirement really is to have different coloured lines (and possibly different lines - e.g. solid, dashed, dotted)

I've spent the past 6 hours researching this, and trying many packages (SGT, jfreechart etc), and so far haven't got anything to work (though I'm not sure what I'm doing is correct)

Can anyone point me in the direction of an example / tutorial, that will produce a line graph (prefereably using what comes with java - or if some external package is needed - full instructions on how to use it)? A "chart building for dummies" type resource?

If I could just find some code that worked to produce a simple line graph, I could then look to extend it to fit my needs

I'm fairly confident with Java itself (though have never developed an applet before), but this has really stumped me

Jonny

Shouldn't be too hard if you just need something simple. Just use g.drawLine(x,y,x,y) repeatedly.

while([points left]) {
[g.drawLine]
}

To do dashes, just make two drawLine calls to to paint the (0-25%) and (50-75%) segments between plot points for example.

I'd recommend JFreeChart. It isn't that hard to use. I'll tell you what, I'll give you a sample piece of code that my teammate wrote on our project that produces a bar graph. You'll have to edit it a lot (hopefully) to get what you want, but it should give you the general idea.

edit:

You'll have to wait for an example from me - my zip drive that has the project on it is in my car's trunk and it's dark out here so I couldn't find it. I'll try to remember to grab it tomorrow.

...I'll tell you what, I'll give you a sample piece of code that my teammate wrote on our project that produces a bar graph. You'll have to edit it a lot (hopefully) to get what you want, but it should give you the general idea.

That would be really appreciated :)

I just want to get something to produce a graph / chart. Then I'm sure I can edit it to get what I want.

anglok, thanks for the suggestions to, I'm sure (once I can get anything visible) they'll come in handy.

On a side note, I'm using eclipse as my IDE. Assuming I'm using jfreechart, what exactly do I need to do with the downloaded Zip file to Java recognises the import commands at the top of the class?

This article has been dead for over six months. Start a new discussion instead.