Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot graph in java and to save as Image

Tags:

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
like image 711
ezzitt Avatar asked Apr 17 '16 18:04

ezzitt


1 Answers

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 :)

like image 148
Nikolas Charalambidis Avatar answered Dec 07 '22 14:12

Nikolas Charalambidis