Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-25-2008, 02:15 PM
Member
 
Join Date: Feb 2008
Posts: 5
sacr83 is on a distinguished road
How to draw a VERTICAL BAR GRAPH in JAVA
hi all. I'm new to java 2D graphs and i want to draw a VERTICAL BAR GRAPH in java.So how i develop it?If you have class library or source code pls send me.The graph shuld be change every one hour.That's mean the graph shuld redraw after one hour.If you have any kind of java class library for VERTICAL BAR GRAPH please send me.

**RegardZ**

ChiNthAka
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-25-2008, 07:52 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.Random; import javax.swing.*; public class HiBars implements Runnable { HiBarPanel hiBarPanel = new HiBarPanel(); Random seed = new Random(); int DATA_MAX = 100; long delay = 20*1000; public HiBars() { Thread thread = new Thread(this); thread.setPriority(Thread.NORM_PRIORITY); thread.start(); } public void run() { while(true) { hiBarPanel.setData(getData(), DATA_MAX); try { Thread.sleep(delay); } catch(InterruptedException e) { break; } } } private int[] getData() { int[] data = new int[4]; for(int i = 0; i < data.length; i++) { data[i] = seed.nextInt(DATA_MAX+1); } return data; } private JPanel getContent() { return hiBarPanel; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new HiBars().getContent()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } } class HiBarPanel extends JPanel { int[] data; int maxValue = 10; final int PAD = 20; public void setData(int[] data, int maxValue) { this.data = data; this.maxValue = maxValue; System.out.printf("data = %s%n", java.util.Arrays.toString(data)); repaint(); } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); // Draw ordinate. g2.draw(new Line2D.Double(PAD, PAD, PAD, h-PAD)); // Draw abcissa. g2.draw(new Line2D.Double(PAD, h-PAD, w-PAD, h-PAD)); double xInc = (double)(w - 2*PAD)/data.length; double scale = (double)(h - 2*PAD)/maxValue; Path2D.Double path = new Path2D.Double(); // Draw data. double x = PAD; double y = h - PAD; path.moveTo(x, y); for(int i = 0; i < data.length; i++) { x = PAD + i*xInc; y = h - PAD - scale*data[i]; path.lineTo(x, y); path.lineTo(x+xInc, y); } path.lineTo(x+xInc, h-PAD); g2.setPaint(new Color(220,220,210)); g2.fill(path); g2.setPaint(Color.blue); g2.draw(path); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-27-2008, 09:14 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
Why would you want to wait an hour that is completely ludicrous.
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-30-2008, 09:09 AM
Member
 
Join Date: Feb 2008
Posts: 5
sacr83 is on a distinguished road
I waite an hour,,,coZ i have existing system for mesure ADSL speeds.That system mesure ADSL speeds one by one hour.SO i have to draw a bar graph for that speeds.Thatz y i waite for an hour for drawing that graph.If you can help me to draw Bar graph coz its an urgent for me.

Thanks a lot for your code

AND

path2D class is not avalable.So how i get that package.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java chart & graph lib saturdaybugs Java 2D 1 04-24-2008 02:59 PM
how to draw an arrow mark using java swing sandhyau AWT / Swing 5 02-07-2008 12:52 PM
what layout to use for vertical alignment? dim_ath AWT / Swing 6 01-20-2008 06:28 PM
How to insert graph in java valery Advanced Java 1 08-06-2007 09:38 PM
how to draw in Java Heather AWT / Swing 2 07-12-2007 12:01 PM


All times are GMT +3. The time now is 08:01 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org