Search code examples
javaswinguser-interfacegraphics2d

Graph using Swing without external library


How to draw (x,y) based graph (line through those points) in Java Swing?

I can not use any external library.


Solution

  • Consider JPanel as your graph paper. Now using different shapes provided by java.awt you can draw different shapes such as Line, Oval, Rectangle etc. The pixels on the screen will be your coordinates of the graph paper. Its very much simple so try it :)