Re: Problems making a Graph
From: IchBin (weconsul_at_ptd.net)
Date: 11/30/04
- Next message: ThomasH: "Missing Graphics in JComponent or JPanel"
- Previous message: Danny Gopie: "Re: specific values in loops"
- In reply to: JS: "Problems making a Graph"
- Next in thread: JS: "Re: Problems making a Graph"
- Reply: JS: "Re: Problems making a Graph"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Nov 2004 18:03:51 -0500
JS wrote:
> 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);
> }
> }
>
>
Could try an open source product called: JFreeChart
at http://www.jfree.org/jfreechart/index.html
-- Thanks in Advance... IchBin __________________________________________________________________________ 'The meeting of two personalities is like the contact of two chemical substances: if there is any reaction, both are transformed.' - Carl Gustav Jung, (1875-1961), psychiatrist and psychologist
- Next message: ThomasH: "Missing Graphics in JComponent or JPanel"
- Previous message: Danny Gopie: "Re: specific values in loops"
- In reply to: JS: "Problems making a Graph"
- Next in thread: JS: "Re: Problems making a Graph"
- Reply: JS: "Re: Problems making a Graph"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|