Problems making a Graph
From: JS (dsa._at_asdf.com)
Date: 11/29/04
- Next message: Eric Sosman: "Re: efficiency problem"
- Previous message: Frances Del Rio: "jsp won't compile..."
- Next in thread: IchBin: "Re: Problems making a Graph"
- Reply: IchBin: "Re: Problems making a Graph"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Nov 2004 23:22:59 +0100
I would like to make a graph like this one:
http://www.cis.ksu.edu/~schmidt/CIS200/gifV6html/Ch5/bargraph.gif
This is what I have, but I am pretty lost on how to get any further.
setBar1 - setBar6 are supposed to be each of the bars and I guess I am
supposed to use setAxes in setBar but I am not sure how.
hope someone can help
----------------------------------------------------------------------------
--------------
import java.awt.*;
import javax.swing.*;
import java.text.*;
class BarGraphWriter extends JPanel
{ private int width;
private int height;
private String sentence1 = "";
private String sentence2 = "";
private String sentence3 = "";
private String sentence4 = "";
private String sentence5 = "";
private String sentence6 = "";
private int x_position;
private int y_position;
public BarGraphWriter(int w, int h)
{ width = w;
height = h;
x_position = width / 5;
y_position = height / 2;
JFrame my_frame = new JFrame();
my_frame.getContentPane().add(this);
my_frame.setTitle("Graph");
my_frame.setSize(width, height);
my_frame.setVisible(true);
}
public void paintComponent(Graphics g)
{ super.paintComponent(g);
g.setColor(Color.red);
g.drawString(sentence1, x_position, y_position);
g.drawString(sentence2, x_position, y_position);
g.drawString(sentence3, x_position, y_position);
g.drawString(sentence4, x_position, y_position);
g.drawString(sentence5, x_position, y_position);
g.drawString(sentence6, x_position, y_position);
}
public void setAxes(int x_pos, int y_pos, String top_label, int y_height)
{
}
public void setBar1(String label, int height, Color c)
{
}
public void setBar2(String label, int height, Color c)
{
}
public void setBar3(String label, int height, Color c)
{
}
public void setBar4(String label, int height, Color c)
{
}
public void setBar5(String label, int height, Color c)
{
}
public void setBar6(String label, int height, Color c)
{
}
}
public class TestGraph
{ public static void main(String[] a)
{ BarGraphWriter e = new BarGraphWriter();
e.setTitle("Days in first four months of the year");
e.setAxes(20, 120, "30", 90);
int scale_factor = 3;
e.setBar1("Jan", 31 * scale_factor, Color.red);
e.setBar2("Feb", 28 * scale_factor, Color.white);
e.setBar3("Mar", 31 * scale_factor, Color.blue);
e.setBar4("Apr", 30 * scale_factor, Color.red);
}
}
- Next message: Eric Sosman: "Re: efficiency problem"
- Previous message: Frances Del Rio: "jsp won't compile..."
- Next in thread: IchBin: "Re: Problems making a Graph"
- Reply: IchBin: "Re: Problems making a Graph"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|