Results 1 to 7 of 7
- 11-20-2012, 01:13 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
How to create Graph of points from array
Hi,
I have to create a Graph from list with two columns of floats. So i have this:
And i need a help with drawing points on a chart. I made simple frame with axes.Java Code:List<Float> getFromFile = new ArrayList<Float>(); Scanner sccan = new Scanner(new FileReader("D:\\Docs\\Java\\test.txt")); while (sccan.hasNext()) { getFromFile.add(sccan.nextFloat()); } sccan.close(); Object maxValue = Collections.max(getFromFile ); Object minValue = Collections.min(getFromFile );
I have problem with getting a max and rest of the points from getFromFile.Java Code:import java.awt.*; import java.awt.event.*; public class Paint extends Canvas { public Paint() { Frame frame = new Frame("Canvas"); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); //Window setSize(900, 600); frame.add(this, "West"); frame.pack(); frame.setResizable(false); frame.setVisible(true); Panel panel1 = new Panel(); panel1.setLayout(new GridLayout(3,1)); panel1.add(new Checkbox("Wyb\u00f3r 1",true)); frame.add(panel1, "Center"); } public void paint(Graphics g) { super.paint(g); //axes g.drawLine(400, 0, 400, 600); g.drawLine(0, 300, 793, 300); //scale for (int i = 0; i < 800; i+=40) { g.drawLine(i, 305, i, 295); } for (int j = 20; j < 600; j+=40) { g.drawLine(395, j, 405, j); } //arrows g.drawLine(395, 5, 400, 0); g.drawLine(405, 5, 400, 0); g.drawLine(789, 295, 793, 299); g.drawLine(789, 305, 793, 299); } }Last edited by enk1du; 11-20-2012 at 01:37 PM.
- 11-20-2012, 04:21 PM #2
Re: How to create Graph of points from array
Why are you using the AWT Canvas which was superseded by the Swing JPanel more than 10 years ago?
Recommended tutorials: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing) and Lesson: Getting Started with Graphics (The Java™ Tutorials > 2D Graphics)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-20-2012, 05:44 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
- 11-20-2012, 06:00 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: How to create Graph of points from array
It's a lot easier than AWT.
Please do not ask for code as refusal often offends.
- 11-20-2012, 08:20 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 3
- Rep Power
- 0
Re: How to create Graph of points from array
OK, I will learn it but any help with implementation of Scanner in AWT?
Last edited by enk1du; 11-20-2012 at 08:25 PM.
- 11-20-2012, 10:05 PM #6
Re: How to create Graph of points from array
Why are you using AWT again? It's deprecated. You should be doing it in Swing. AWT is over a decade old, there is no use in learning it at this point, it is more trouble than it is worth.
- 11-21-2012, 09:39 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
create moving points with respect to time
By life4menu in forum Java AppletsReplies: 44Last Post: 03-15-2012, 06:30 PM -
[jFreeChart] Converting screen-points to points, which are relative to the axis
By fyaxic in forum AWT / SwingReplies: 1Last Post: 08-11-2011, 10:46 AM -
Java Sorting Array of points!
By Jcbconway in forum Advanced JavaReplies: 26Last Post: 10-27-2010, 04:07 AM -
Drawing 2D multi axis graph with option to get the coordinates of 2 points (user sel)
By saachin2005 in forum New To JavaReplies: 5Last Post: 10-01-2010, 09:26 PM -
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08-24-2008, 12:30 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks