Page 1 of 2 12 LastLast
Results 1 to 20 of 28
Like Tree8Likes

Thread: How to plot graph in java for given samples

  1. #1
    annesteve31 is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Question How to plot graph in java for given samples

    Hi, I am new to java. I wana create a java program that can plot graph for example with the following data:
    x-axis: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
    y-axis: 21 14 18 03 86 88 74 87 54 77 61 55 48 60 49 36 38 27 20 18

    I have installed jdk1.6.0_06. Can I know where to find the code for this?
    Can jdk java program do this or do I need other type of java?
    Please guide. Thax

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    
    public class GraphingData extends JPanel {
        int[] data = {
            21, 14, 18, 03, 86, 88, 74, 87, 54, 77,
            61, 55, 48, 60, 49, 36, 38, 27, 20, 18
        };
        final int PAD = 20;
    
        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-1);
            double scale = (double)(h - 2*PAD)/getMax();
            // Mark data points.
            g2.setPaint(Color.red);
            for(int i = 0; i < data.length; i++) {
                double x = PAD + i*xInc;
                double y = h - PAD - scale*data[i];
                g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
            }
        }
    
        private int getMax() {
            int max = -Integer.MAX_VALUE;
            for(int i = 0; i < data.length; i++) {
                if(data[i] > max)
                    max = data[i];
            }
            return max;
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new GraphingData());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        }
    }

  3. #3
    annesteve31 is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    Thanks hardwired.
    Wow, this is so amazing. I get this.

    But is it possible to link the line together and label the x and y axis? Giving title to it?

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import javax.swing.*;
    
    public class GraphingData extends JPanel {
        int[] data = {
            21, 14, 18, 03, 86, 88, 74, 87, 54, 77,
            61, 55, 48, 60, 49, 36, 38, 27, 20, 18
        };
        final int PAD = 20;
    
        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));
            // Draw labels.
            Font font = g2.getFont();
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            float sh = lm.getAscent() + lm.getDescent();
            // Ordinate label.
            String s = "data";
            float sy = PAD + ((h - 2*PAD) - s.length()*sh)/2 + lm.getAscent();
            for(int i = 0; i < s.length(); i++) {
                String letter = String.valueOf(s.charAt(i));
                float sw = (float)font.getStringBounds(letter, frc).getWidth();
                float sx = (PAD - sw)/2;
                g2.drawString(letter, sx, sy);
                sy += sh;
            }
            // Abcissa label.
            s = "x axis";
            sy = h - PAD + (PAD - sh)/2 + lm.getAscent();
            float sw = (float)font.getStringBounds(s, frc).getWidth();
            float sx = (w - sw)/2;
            g2.drawString(s, sx, sy);
            // Draw lines.
            double xInc = (double)(w - 2*PAD)/(data.length-1);
            double scale = (double)(h - 2*PAD)/getMax();
            g2.setPaint(Color.green.darker());
            for(int i = 0; i < data.length-1; i++) {
                double x1 = PAD + i*xInc;
                double y1 = h - PAD - scale*data[i];
                double x2 = PAD + (i+1)*xInc;
                double y2 = h - PAD - scale*data[i+1];
                g2.draw(new Line2D.Double(x1, y1, x2, y2));
            }
            // Mark data points.
            g2.setPaint(Color.red);
            for(int i = 0; i < data.length; i++) {
                double x = PAD + i*xInc;
                double y = h - PAD - scale*data[i];
                g2.fill(new Ellipse2D.Double(x-2, y-2, 4, 4));
            }
        }
    
        private int getMax() {
            int max = -Integer.MAX_VALUE;
            for(int i = 0; i < data.length; i++) {
                if(data[i] > max)
                    max = data[i];
            }
            return max;
        }
    
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new GraphingData());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        }
    }
    Aman Seth, yura37 and Lämarão like this.

  5. #5
    annesteve31 is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi hardwired, the graph looks a better now. :)
    So happy for my 1st time to see that can use java code to plot graph.

    How to show out the value at both the x and y axis bar? Can put a title likes "Graph of Y-Data vs X-Data" on the top?

  6. #6
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Can put a title likes "Graph of Y-Data vs X-Data" on the top?
    Yes. The GraphingData example shows how to position text where you want.

  7. #7
    annesteve31 is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    Ok, thanks for the guide. :confused:Btw wat I mean is that I wan to show the axis value of
    x-axis: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
    y-axis: 21 14 18 03 86 88 74 87 54 77 61 55 48 60 49 36 38 27 20 18
    at the graph, I mean the number values at both of the x and y bar of the graph. How to do it?:p
    Last edited by annesteve31; 04-26-2008 at 08:25 AM.

  8. #8
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    In the paintComponent method you'll find some values you can use to navigate along the axes.
    Java Code:
    // The space between values along the abcissa.
    double xInc = (double)(w - 2*PAD)/(data.length-1);
    // Scale factor for ordinate/data values.
    double scale = (double)(h - 2*PAD)/getMax();
    To position the abcissa labels:
    Java Code:
    // For the x location you start with PAD to move
    // to the graph origin and count "xInc" intervals
    // to the desired value location:
    x = PAD + x_axisDataIndex * xInc
    // The vertical positioning is the same as used to
    // draw the abcissa label:
    sy = h - PAD + (PAD - sh)/2 + lm.getAscent();
    To locate labels for ordinate values:
    Java Code:
    // Space between axis and label.
    final int SPAD = 2;
    ...
    String s = String.valueOf(data[i]);
    float sw = (float)font.getStringBounds(s, frc).getWidth();
    float sx = PAD - sw - SPAD;
    // For the ordinate you count from the bottom up
    // (component/graphics origin is at upper left).
    // The actual value location on the ordinate will be
    // y = h - PAD - scale*data[i]
    // which you would use if you wanted to draw a tick mark on the
    // ordinate.
    // Offset this to locate the text origin. This usually requires
    // some experimenting. To start you can try something like
    float sy = h - PAD - scale*data[i] + lm.getAscent()/2;
    g.drawString(s, sx, sy);
    "sw" and "sh" are the width and height of the string.

  9. #9
    criminal is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    Hi Hardwired
    I used your program. You only plot on the +ve x, +ve y area. Can you please modify the program to plot on any area? Meanwhile, I'm also trying here, but I'm not familiar with AWT so I will take longer to do it than you would.

    thanks.

  10. #10
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Look at jfreechart. Free, open source Java library that will plot nearly anything, any format, with titles, legends colors, etc.

    Software re-use. Don't rewrite the wheel

  11. #11
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.util.Random;
    import javax.swing.*;
    
    public class Plot2D {
        Random seed = new Random();
        final int SIZE = 8;
        final double MAX = 10.0;
        PlotPanel plotPanel;
    
        private double[] getData(double min, double max) {
            double[] d = new double[SIZE];
            for(int i = 0; i < SIZE; i++) {
                d[i] = min + seed.nextDouble()*(max - min);
                //System.out.printf("%5.1f ", d[i]);
            }
            //System.out.println();
            return d;
        }
    
        private JPanel getContent() {
            double[] x = getData(-MAX, MAX);
            double[] y = getData(-MAX, MAX);
            plotPanel = new PlotPanel(x, y);
            return plotPanel;
        }
    
        private JPanel getUIPanel() {
            JButton button = new JButton("change data");
            JRadioButton[] rbs = new JRadioButton[5];
            final ButtonGroup group = new ButtonGroup();
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int index = Integer.parseInt(
                        group.getSelection().getActionCommand());
                    double xMin = -MAX, xMax = MAX, yMin = -MAX, yMax = MAX;
                    switch(index) {
                        case 0:
                            xMax = -5;
                            break;
                        case 1:
                            xMin = 5;
                            break;
                        case 2:
                            break;
                        case 3:
                            yMax = -5;
                            break;
                        case 4:
                            yMin = 5;
                    }
                    double[] x = getData(xMin, xMax);
                    double[] y = getData(yMin, yMax);
                    plotPanel.setData(x, y);
                }
            });
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            String minus = "<html>\u2013";
            String[] ids = {
                "<html>\u2013x", "+x", "<html>+/\u2013x&y", "<html>\u2013y", "+y"
            };
            for(int i = 0; i < rbs.length; i++) {
                rbs[i] = new JRadioButton(ids[i], i == 2);
                rbs[i].setActionCommand(String.valueOf(i));
                group.add(rbs[i]);
                panel.add(rbs[i], gbc);
            }
            panel.setBorder(BorderFactory.createEtchedBorder());
            gbc.weightx = 1.0;
            panel.add(button, gbc);
            return panel;
        }
    
        public static void main(String[] args) {
            Plot2D test = new Plot2D();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(test.getContent());
            f.add(test.getUIPanel(), "Last");
            f.setSize(400,400);
            f.setLocation(50,50);
            f.setVisible(true);
        }
    }
    
    class PlotPanel extends JPanel {
        double[] x;
        double[] y;
        double xMin;
        double xMax;
        double yMin;
        double yMax;
        final int PAD = 20;
        final boolean DEBUG = false;
        boolean firstTime;  // Set at end of setData method.
    
        public PlotPanel(double[] x, double[] y) {
            setData(x, y);
        }
    
        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();
            double xScale = (w - 2*PAD)/(xMax - xMin);
            double yScale = (h - 2*PAD)/(yMax - yMin);
            if(firstTime)
                System.out.printf("xScale = %.1f  yScale = %.1f%n",
                                   xScale, yScale);
            Point2D.Double origin = new Point2D.Double(); // Axes origin.
            Point2D.Double offset = new Point2D.Double(); // Locate data.
            if(xMax < 0) {
                origin.x = w - PAD;
                offset.x = origin.x - xScale*xMax;
            } else if(xMin < 0) {
                origin.x = PAD - xScale*xMin;
                offset.x = origin.x;
            } else {
                origin.x = PAD;
                offset.x = PAD - xScale*xMin;
            }
            if(yMax < 0) {
                origin.y = h - PAD;
                offset.y = origin.y - yScale*yMax;
            } else if(yMin < 0) {
                origin.y = PAD - yScale*yMin;
                offset.y = origin.y;
            } else {
                origin.y = PAD;
                offset.y = PAD - yScale*yMin;
            }
            if(firstTime) {
                System.out.printf("origin = [%6.1f, %6.1f]%n", origin.x, origin.y);
                System.out.printf("offset = [%6.1f, %6.1f]%n", offset.x, offset.y);
            }
    
            // Draw abcissa.
            g2.draw(new Line2D.Double(PAD, origin.y, w-PAD, origin.y));
            // Draw ordinate.
            g2.draw(new Line2D.Double(origin.x, PAD, origin.x, h-PAD));
            g2.setPaint(Color.red);
            // Mark origin.
            g2.fill(new Ellipse2D.Double(origin.x-2, origin.y-2, 4, 4));
    
            // Plot data.
            g2.setPaint(Color.blue);
            for(int i = 0; i < x.length; i++) {
                double x1 = offset.x + xScale*x[i];
                double y1 = offset.y + yScale*y[i];
                if(firstTime)
                    System.out.printf("i = %d  x1 = %6.1f  y1 = %.1f%n", i, x1, y1);
                g2.fill(new Ellipse2D.Double(x1-2, y1-2, 4, 4));
                g2.drawString(String.valueOf(i), (float)x1+3, (float)y1-3);
            }
    
            // Draw extreme data values.
            g2.setPaint(Color.black);
            Font font = g2.getFont();
            FontRenderContext frc = g2.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("0", frc);
            String s = String.format("%.1f", xMin);
            float width = (float)font.getStringBounds(s, frc).getWidth();
            double x = offset.x + xScale*xMin;
            g2.drawString(s, (float)x, (float)origin.y+lm.getAscent());
            s = String.format("%.1f", xMax);
            width = (float)font.getStringBounds(s, frc).getWidth();
            x = offset.x + xScale*xMax;
            g2.drawString(s, (float)x-width, (float)origin.y+lm.getAscent());
            s = String.format("%.1f", yMin);
            width = (float)font.getStringBounds(s, frc).getWidth();
            double y = offset.y + yScale*yMin;
            g2.drawString(s, (float)origin.x+1, (float)y+lm.getAscent());
            s = String.format("%.1f", yMax);
            width = (float)font.getStringBounds(s, frc).getWidth();
            y = offset.y + yScale*yMax;
            g2.drawString(s, (float)origin.x+1, (float)y);
            if(firstTime)
                System.out.println("------------------------------");
            firstTime = false;
        }
    
        public void setData(double[] x, double[] y) {
            if(x.length != y.length) {
                throw new IllegalArgumentException("x and y data arrays " +
                                                   "must be same length.");
            }
            this.x = x;
            this.y = y;
            double[] xVals = getExtremeValues(x);
            xMin = xVals[0];
            xMax = xVals[1];
            if(DEBUG)
                System.out.printf("xMin = %5.1f  xMax = %5.1f%n", xMin, xMax);
            double[] yVals = getExtremeValues(y);
            yMin = yVals[0];
            yMax = yVals[1];
            if(DEBUG)
                System.out.printf("yMin = %5.1f  yMax = %5.1f%n", yMin, yMax);
            firstTime = DEBUG;
            repaint();
        }
    
        private double[] getExtremeValues(double[] d) {
            double min = Double.MAX_VALUE;
            double max = -min;
            for(int i = 0; i < d.length; i++) {
                if(d[i] < min) {
                    min = d[i];
                }
                if(d[i] > max) {
                    max = d[i];
                }
            }
            return new double[] { min, max };
        }
    }
    XTone likes this.

  12. #12
    sirine is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    i have a similar question. I need some help for a project at the university.
    I have written 3 classes (function, parabola and polynomial), which represent functions with a variable . I must to extend my function class with a method named public void plot(double xmin, double xmax), which opens a frame with the graph of determined function. the parameter xmin and xmax give the x-area, where the grapf should be drawn. A labeld coordinate axis must also appear in the frame. Can you help me?

    Here are my classes :

    Java Code:
    /**
     * Class to respresent parabola functions
     */
    public class Function{
    	
        /**
         * some static constants 
         */
        public final static int n = 1000;
        public final static double eps = 0.000000001;
        public final static Function NULL=new Function(){
            public double map(double x){return 0.0; }
            public String toString() {return "0.0"; }
        };
        
        
        /**
         * Defines the mapping of the function. The default mapping is not-defined
         * so the return value is Double.NaN for instances of this class. Subclass
         * should override this method to define the mapping
         * @param x
         * @return
         */
        public double map(double x){return Double.NaN;}
        
        /**
         * Evaluates the function at each arguemt of the array
         * @param x array of function values
         * @return
         */
        public double[] map(double[] x){
            double[] y=new double[x.length];
            for (int i=0; i<x.length; i++) y[i]=map(x[i]);
            return y;
        }
        
        /**
         * Access to the derivation of the Function instances. Subclass should
         * override this method. Use Double.NaN at non-differntiable positions
         * @return derivative of this function instance
         */
        public Function derivate(){
            return this;
        }
    
        /**
         * a
         * approximate the integral of this function using n boxes
         * @param a stating of the integration
         * @param b ending of the integration
         * @param n number of boxes (equal width)
         * @return approximation of the integral over [a,b] of this function
         */    
        public double integrate(double a, double b, int n){
            double delta=(b-a)/(double)n;
            double area=0;
            for (double i=0; i<n; i++) area+=map(a+i*delta);
            return area*delta;
        }
    
        /**
         * If possible this method should return the exact integral value. 
         * Subclasses should override this method.
         * The default is to call the approximation integrate(a,b,n).
         * @param a stating of the integration
         * @param b ending of the integration
         * @param n number of boxes (equal width)
         * @return integral over [a,b] of this function
         */
        public double integrate(double a, double b){
            return this.integrate(a,b,this.n);
        }
    
        /** 
         * Computes a zero-crossing using the newton iteration
         * @param x_0 initial argument
         * @return Zero-Crossing or Double.NaN
         */
        public double newtonIteration(double x_0){
            double d=42.0;
            Function f_1=this.derivate();
            for (int i=0; ((++i<this.n) && (Math.abs(d)>eps)); x_0+=d)
                d=-map(x_0)/f_1.map(x_0);
            return (Math.abs(d)>eps) ? Double.NaN : x_0;
        }
        
        /**
         * String representation of this function
         * @return "undefined"
         */
        public String toString(){
            return "undefined";
        }
    }
    Java Code:
    /**
     * Class to respresent parabola functions
     *
     */
    public class Parabola extends Polynomial{
        
        /**
         * Constructor for a parabola object ax? + bx + c
         * @param a coefficient for x^2
         * @param b coefficient for x^1
         * @param c coefficient for x^0
         */
        public Parabola(double a, double b, double c){        
            super(new double[] {c,b,a});        
        }
        
        /**
         * Compute the Zero Crossings of the parabola
         * @return zero-crossings, i.e. x with f(x)=0
         */
        public double[] zeroCrossing(){
            double c=map(0);
            double b=map(0.5)-map(-0.5);
            double a=map(1)-b-c;
    
            //Diskriminante
            double d = b*b - 4.0*c*a;
            
            if (this.getDegree()<=1){
                if (b==0) return new double[0];
                else return new double[] {-c/b};        
            }
                    
            if (d==0) return new double[] {-0.5*b/a};
            if (d<0) return new double[0];
            
            return new double[] { 0.5*(-b-Math.sqrt(d))/a, 0.5*(-b+Math.sqrt(d))/a};
        }
    
    }
    Java Code:
    /**
     * Class to respresent polynomial functions
     *
     * 
     * Bug in limPosInf() for constant functions repaired
     * 
     */
    public class Polynomial extends Function{
    
        // Koeffizienten des Polynoms
        private double[] a=new double[0];
        
        /**
         * Constructor for a polynomial function, sum a[i] * x^i
         * @param a coeffients of the polynomial function
         */
        public Polynomial(double[] a){
            int deg = a.length-1;
            for (int i=deg; ((i>=0) & (a[i]==0.0)) ; i--) deg--;
            this.a = new double[deg+1];
            for (int i=0; i<=deg; i++) this.a[i]=a[i];
        }
        
        /**
         * Access to the degree of the polynomial, i.e. the maximal "nonzero" power
         * @return degree of the polynomial
         */
        public int getDegree(){
            return a.length-1;
        }
        
        /**
         * Access to the derivative of the polynomial
         * @return the derivative of the polynomial
         */
        public Function derivate(){
            if (this.getDegree()==0) return Function.NULL;
            double[] b=new double[this.a.length-1];
            for (int i=0; i<b.length; )
                b[i]=((double)++i)*this.a[i];
            return new Polynomial(b);
        }
        
        /**
         * Computes the integral of the polynomial over an interval
         * @param a begining of the integration interval
         * @param b ending of the integration interval
         * @return integral over [a,b] of polynomial
         */
        public double integrate(double a, double b){
            double[] a_=new double[this.a.length+1];
            a_[0]=0.0;
            for (int i=1; i<a_.length; i++)
                a_[i]=this.a[i-1]/((double)i);
            Polynomial F = new Polynomial(a_);
            return F.map(b)-F.map(a);
        }
        
        /**
         * function value of the polynomial at x
         * @param x argument of the function
         * @return value f(x) of the function
         */
        public double map(double x){
            double y=0.0;
            for (int i=getDegree(); i>=0; i--) y=y*x+a[i];
            return y;
        }
        
        /**
         * computes the limit for x->oo
         * @return limit for x->oo
         */
        public double limPosInf(){
            if (getDegree()==0) return map(0);
            return (a[getDegree()]>0)
                    ? Double.POSITIVE_INFINITY
                    : Double.NEGATIVE_INFINITY;
        }
    
        /**
         * computes the limit for x->-oo
         * @return limit for x->-oo
         */
        public double limNegInf(){
            return (getDegree()%2==0)
                    ?  limPosInf()
                    : -limPosInf();
        }
        
        /** String representation
         * @return awesome string representation
         */
        public String toString(){
            //sorry for this bad code ;)
            String s="";
            String vz="";
            for (int i=0; i<a.length; i++)
                if (a[i]!=0) {
                    s=((i==0) ? a[i] : (a[i]==1) ? "" : (a[i]==-1) ? "-" : ""+a[i])
                     +((i==0) ? "" :(i==1) ? "x" : "x^"+i)//aktuelle Potenz
                     +vz                                  //zusätzliches Vorzeichen
                     +s;                                  //Kleinere Potenzen
                    
                    //Berechnung des aktuellen Vorzeichens
                    if (a[i]>0 ) vz="+"; else vz="";
                }            
    
            return s;
        }
    }

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Would it be asking too much to see an attempt by you to plot it first?

  14. #14
    almostanangel is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Talking

    Quote Originally Posted by fishtoprecords View Post
    Look at jfreechart. Free, open source Java library that will plot nearly anything, any format, with titles, legends colors, etc.

    Software re-use. Don't rewrite the wheel
    I have been trying to use jfreechart for DAYS!!! im getting fustrated because i am able to download the files for all the graphs which is great ... lol but then when i try to open them in Netbeans i can not see the Project file / java file to launch the bloody graph.


    You can probably tell im now getting fustrated by this re inventing the wheel would be easier. Please can you tell me what to do with these jfreechart zip files once i have unzipped then to launch the graph

  15. #15
    cvubando is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default Help!

    Can somebody help me plot the function x0 + v0t – gt^2/2, which is the displacement in meters after t seconds when an object is thrown straight up from initial position x0 at velocity v0 meters per second and where g is the constant 9.78033 (gravity).

    Using StdDraw, I need to set the x scale to 20 and the y scale to 500.

    Any help would be much appreciated. Thanks!

  16. #16
    BlurBlur is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default

    Hi,i had face some graph plotting problem for my project too. I need to plot my graph from data loading by Excel file. And there will be 2 lines in the graph since i want to do graph matching for 2 set of data. Is it possible to do that? Anyone can help me? Thx you. =)

  17. #17
    newUser is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Hi Hardwired

    Can u pls provide a full program that draws a line graph. I want X axis and Y axis scale to be displayed as well. Please do the needful

    Thanks In Advance

  18. #18
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by newUser View Post
    Can u pls provide a full program that draws a line graph. I want X axis and Y axis scale to be displayed as well. Please do the needful
    Do not hijack some one else's thread with an unrelated question. Start your own. And the answer will be the same, use JFreeChart. It has examples. and is well documented.

  19. #19
    newUser is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    Sorry for hijacking this thread...since my query was highly related to this thread I continued with this thread.

    Regarding my query... I can not use JFree since it is a third party tool and it occupied 1.23 MB space. So I need to draw graph through java.

    Can u provide me the full program to draw a line graph along with X and Y axis labels.

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Can u provide me the full program to draw a line graph along with X and Y axis labels.
    No. This is not a get code on demand service.

    Now if you create this program and then run into problems, by all means come on back and ask a question regarding your code, and many will be glad to help you. Otherwise all we can tell you is to please do it yourself. Best of luck.

Page 1 of 2 12 LastLast

Similar Threads

  1. Plot 2D graph in Java from RS-232 data
    By spratana in forum Java 2D
    Replies: 4
    Last Post: 02-11-2009, 06:49 PM
  2. Java chart & graph lib
    By saturdaybugs in forum Java 2D
    Replies: 1
    Last Post: 04-24-2008, 01:59 PM
  3. Need Help for Dot Plot Graph
    By BHCluster in forum Java 2D
    Replies: 5
    Last Post: 04-15-2008, 02:54 PM
  4. How to insert graph in java
    By valery in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 08:38 PM
  5. Java cert exam samples
    By orchid in forum New To Java
    Replies: 5
    Last Post: 06-04-2007, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •