Search code examples
javagraphics2djava-2d

How to draw a two dimensional graphic at Java?


I have 2 different lists. Each of them holds x and y value pairs(they have both positive and negative values). How can I draw them on a 2D axis? I want to put points for every value and they will blue for first list and red for second list.

My lists' type:

List<List<Double>>

List<Double> inside of List<...> has 2 variables, first of it for x value and the second one is for y value.

However just I need to how to draw a two dimensional graphic at Java(desktop application) and put points wherever I want, improving code for my variables is less important.

PS:

I want the more and more simple of that kind of graphic: enter image description here

Something like:

enter image description here


Solution

  • you could use a library like http://www.jfree.org/jfreechart/ (LGPL-License) there are lots of examples around the web, and it's quite easy to use.

    here's an example, that seems to match your requirements:

    http://www.java2s.com/Code/Java/Chart/JFreeChartMarkerDemo1.htm