ezzitt
ezzitt

Reputation: 117

How to plot graph in java and to save as Image

I would create a java program to save a graph as image PNG for example with the following data:

x-axis: 01  02  03  04  05  06  07  08  09  10 
y-axis: 610 635 659 680 699 712 722 732 736 749

Upvotes: 5

Views: 10048

Answers (3)

Damian JK
Damian JK

Reputation: 579

Try to use JGraphX to create graphs in java. You could find maven dependency on github. To save tree graph try java JGraphx save as an image

Upvotes: 1

Bart Mensfort
Bart Mensfort

Reputation: 1088

Try dotty.exe to create graphs. Use graphviz open source.

Upvotes: 1

Nikolas
Nikolas

Reputation: 44368

Theoretically you'd do that following these steps. Actually you have to first learn how to work with particular parts:

  1. Save these coordinates to an array or a List.
  2. Draw the content using javafx or any graphics library.
  3. Read the: https://community.oracle.com/thread/2450090?tstart=0
  4. In case of using javafx, you can capture its canvas with canvas.snapshot(..)
  5. Save the file using ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", file);
  6. Hooray!

I recommend you to start with learning all about variables, data types, arrays, loops and lists/maps. Don't start with 2D drawing unless you can handle with data :)

Upvotes: 2

Related Questions