Graph applet

hello,
i wish to draw a line graph in a certain region(ex. rectangle),even when exceeds the dimentions of the rectangle i want to display the current plot...
for ex. http://java.sun.com/products/java-media/2D/samples/java2demo/Java2Demo.html
in Arcs_Curves one can see a line plot at rightbottom ,shifting the curve to left,i need the same logic ,ofcourse i have the running curve..
just i need the logic how the curve is moving to left.
any suggestons are accepted...a few lines of code is too good...
thank you,
bhaskar..

thanks for the comments,but i mentioned i have the graph,just i need to fit in a certain area...
here i am sending an example of my code...
import java.awt.*;
import java.awt.Button;
import java.awt.event.*;
public class MyApplet extends java.applet.Applet implements ActionListener, Runnable {
int xSPos,ySPos,xOrig,yOrig,width,height;
private Thread run = null;
private boolean running;
private Image bufferImage;
private Graphics bufferGraphics;
Button start;
public void init() {
setBackground(Color.white);
setSize(450,300);
start = new Button("Start");
add(start);
start.addActionListener(this);
public void actionPerformed(ActionEvent ae) {
try {       
System.err.println( "run is: "+run );
if( run != null ) {
run.interrupt();
run.join();
run = new Thread(this);
run.start();
} catch( InterruptedException ie ) {
repaint();
public void paint(Graphics g) {
update(g);
public void update(Graphics g) {
     if(bufferImage != null)
          g.drawImage(bufferImage,0,0,this);
public void run() {
running = false;
int W = 0,H = 0;
     if(bufferGraphics == null) {
          Dimension d = getSize();
          W = d.width;
          H = d.height;
          bufferImage = createImage(W,H);
          bufferGraphics = bufferImage.getGraphics();
xSPos = 50;
ySPos = 80;
width = 200;
height = 100;
xOrig = xSPos;
yOrig = ySPos+height;
int xLocP = xOrig;
int yLocP = yOrig;
int xMax = 150;
int yMax = 90;
for(int i=0; i<=500; i++) {
int xLoc = xOrig;
int yLoc = yOrig;
xLoc = xLoc+Math.round(width*i/xMax);
yLoc = yLoc-Math.round(height*i/yMax);
bufferGraphics.setColor(Color.black);
bufferGraphics.drawRect(xSPos,ySPos,width,height);
bufferGraphics.setColor(Color.blue);
bufferGraphics.drawLine(xLocP, yLocP, xLoc, yLoc);
try {
Thread.sleep(350);
catch(Exception ex) {
          repaint();
xLocP = xLoc;
yLocP = yLoc;
run = null;
     running = false;
bufferGraphics = null;
     //repaint();
from this output when the line crosses the dimentions of rectangle,the old points should delete so that there will be space to draw for new values...got my point...
once more thankyou...

Similar Messages

  • Help with graph applet code

    I cant figure out how to finsih this... I am creating an applet that draws a quadratic equation according to the parameters in the html file...
    Here is the first class... I think its ok:
    import java.awt.*;
    import java.applet.*;
    public class Graph extends Applet
         public void init()
             int in1 = Integer.parseInt(getParameter("a"));
             int in2 = Integer.parseInt(getParameter("b"));
             int in3 = Integer.parseInt(getParameter("c"));
              int a=1;
              int b=1;
              int c=1;
              if( in1!=0)
                                                 a=in1;
              if( in2!=0)
                 b=in2;
              if( in3!=0)
                 c=in3;
              Dimension size = getSize();
              int width = size.width;
              String msg = "Quadratic Equation: y = ax^2 + bx + c";
              Label bottom = new Label(msg);
              Label header = new Label("Quadratic Equation");
              setLayout(new BorderLayout());
              GraphCanvas canvas = new GraphCanvas(width,a,b,c);
              add(header,BorderLayout.NORTH);
              add(canvas,BorderLayout.CENTER);
              add(bottom,BorderLayout.SOUTH);
    }and here is the GraphCanvas class... which I can't figure out how to finish. hints and help would be appriciated:
    import java.awt.*;
    import java.applet.*;
    public class GraphCanvas extends Canvas
         private double density;
         private final int XMAX = 10;
         private final int XMIN = -10;
        private final int YMAX = 10;
         private final int YMIN = -10;
         private double x;
         private double y;
         public GraphCanvas(int dimension, double a, double b, double c)
             dimension = 20;
              density=dimension/(XMAX-XMIN)
              y=a*x^2+b*x+c;
         public void paint(Graphics g)
              drawGrid(g);
              graphQuadratic(g);
         public void drawGrid(Graphics g)
         public void graphQuadratic(Graphics g)
              for (x=-10;x<=10;x+=0.02)
                   y=x^2+x+1;
                   moveTo(x,y);
                   drawTo(g,x,y);
         public void moveto(double x, double y)
         public void drawto(double x, double y, Graphics g)
    }it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind wrapped around.

    You may want to test the equation first, then save a "y-offset" value. Otherwise the images you draw may be off the canvas. Do this before drawing the scales (which I presume would appear in your drawGrid method), I'd suggest. Also use the offset when drawing the curve itself.
    it;s mainly the drawTo and moveTo methods that i am haveing trouble getting my tired mind
    wrapped around.Well, you're the one that wants to use them. What do you expect them to do?

  • Help needed in plotting line graph!

    Hi i need help in plotting a line graph complete with both axes shown,plus the legend on the side shown.
    Pls help!!!!
    rgds

    Here's a simple line graph applet I did some time backimport java.awt.*;
    public class LineGraff extends java.applet.Applet{
       double []toGraff = {6.0, -14.0, -164.0, -210.0, 108.0, 770.0,
                                1354.0, 896.0, -572.0, -1348.0, -780.0, -108.0};
       double []numsFromFile = {6.0, -14.0, -164.0, -210.0, 108.0, 770.0,
                                1354.0, 896.0, -572.0, -1348.0, -780.0, -108.0};
       int max, min, size, Hscale;
       double Vscale;
       public void init(){
          size = numsFromFile.length-1;
          java.util.Arrays.sort(numsFromFile);
          max = (int) numsFromFile[size];
          min = (int) numsFromFile[0];
          Vscale = max-min;
          Vscale = 200/Vscale;
         Hscale = Math.round(300/size);
       public void paint(Graphics g) {
          g.setFont(new Font("Arial",0,14));
          g.drawString("Example app: drawing a graph from a double array",25,18);
          g.setFont(new Font("Arial",0,10));
          g.setColor(Color.blue);
          g.fillRect(10,20,365,230);
          g.setColor(Color.cyan);
          g.drawLine(25,25,25,225);
          g.drawLine(25,140,330,140);
          g.setColor(Color.white);
          int intA = 30, intB = 0, intC = 0;
          int intD = (int) (Math.round(140 - (Vscale * toGraff[0])));
             for(int i=1; i <= size; i++) {
               intC = intA + Hscale;
               intB = intD;
               intD = (int) (Math.round(140 - (Vscale * toGraff[ i ])));
               g.drawLine(intA, intB, intC, intD);
                  if(toGraff[ i ] > 0)
                     g.drawString(Double.toString(toGraff[ i-1 ]), intA+6, intB-3);
                  else
                     g.drawString(Double.toString(toGraff[ i-1 ]), intA+6, intB+8);
               intA += Hscale;
          g.drawString(Double.toString(toGraff[size]), intA+6, intD-3);    
    }

  • Multiple Applet Instances

    Hi.
    I'm writing an asp application that reports on performance indicators.
    When you click on an item in the report, a window opens to an asp page that interrogates a database for historical data on the selected indicator, passes the results to the client via hidden fields, and the client converts this data into X/Y coordinates that are then passed to an applet that draws a graph. Trouble is, when several instances of the graph window are opened they get overlaid on to each other and when you bring focus back to an overlaid graph, the graph gets re-drawn with the results of the most recent instance of the graph class (I hope my terminology is correct here!) not the instance that it created when it was first opened. The end result is that every instance of the graph window that looses then regains visibility shows the same graph.
    Unexpected!
    I don't have enough Java (yet) to know where to look for a solution, can someone shove me in the right direction?
    Thanks.
    Neil.

    There are only 3 ways I can think of for that to happen.
    1. Your graph applet is querying the db on its own somehow, and when it refreshes, it gets the data from the last query
    2. Your web browser (ie?) gets confused, reloads, and again, you get the new data from the db
    3. Web browser somehow gets its applet cache screwed up and displays the wrong one

  • A bar graph problem

    hi all,
    sorry if my question is not clear, try my best to describe.
    i currently creating a bar graph applet, where this applet take different "group" of data / value, e.g. (68, 268,2680, 28 and 8). and here the maximum value is 2680, other group may NOT so. so for being the bar graph display, i have an applet that has a "fixed" maximum width of 700, i need my bar graph to have only 10 columns and also i need to minus out 10 from each column for other purposes, so i take (700 / 10) - 10 = 60, but here come the real problem, if i take 268 * 60 = 16080, that is incorrect! That is i know that i had to divide the 700 with 1000, because (700 / 1000) - (10 / 1000) = 0.69, then 268 * 0.69 = 184.92, that seem OK! but, but it still ran out of the expected result, the bar width will be much more shorter than expected (only those higher data value), why? my code will be as follow:
       if (highestWidth >= 1001)
          maxDetector = 10000;
       else if (highestWidth >= 101)
           maxDetector = 1000;
       else if (highestWidth >= 11)
           maxDetector = 100;
       else
           maxDetector = 10;
       maxSingleWidth = (axisPanel.getWidth() / maxDetector) - (10 / (maxDetector / 10));so, at for loop:
    for (i=0; i <= 9; i++){
       barPanel.setBounds(x, y, (dataValue * maxSingleWidth), height);
    any help will be very very much appreciated!!!

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    public class BarGraph
        public BarGraph()
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new BarGraphPanel());
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        public static void main(String[] args)
            new BarGraph();
    class BarGraphPanel extends JPanel
        int[] data;
        int maxValue;
        Font font;
        NumberFormat nf;
        final int PAD = 40;
        public BarGraphPanel()
            data = new int[] { 75, 12, 23, 44, 98, 32, 53, 6 };
            font = new Font("lucida sans demibold", Font.PLAIN, 15);  // j2se 1.3+
            nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(1);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            double w = getWidth();
            double h = getHeight();
            // ordinate
            g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
            // ordinate labels
            String[] labels = getLabels();
            float labelScale = (float)(h - 2*PAD)/(labels.length - 1);
            g2.setFont(font);
            FontRenderContext frc = g2.getFontRenderContext();
            for(int j = 0; j < labels.length; j++)
                float width = (float)font.getStringBounds(labels[j], frc).getWidth();
                float height = font.getLineMetrics(labels[j], frc).getAscent();
                float x = (PAD - width)/2;
                float y = (float)(PAD + j*labelScale + height/2);
                g2.drawString(labels[j], x, y);
            // abcissa
            g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
            // plot data
            g2.setPaint(Color.red);
            double xInc = (w - 2*PAD) / data.length;
            double yScale = getValueScale(h);
            double x1, y1, x2, y2;
            for(int j = 0; j < data.length; j++)
                x1 = PAD + j * xInc;
                y1 = h - PAD;
                x2 = x1 + xInc;
                y2 = y1 - data[j] * yScale;
                g2.draw(new Line2D.Double(x1, y1, x1, y2));    // left vertical
                g2.draw(new Line2D.Double(x1, y2, x2, y2));    // top of bar
                g2.draw(new Line2D.Double(x2, y2, x2, y1));    // right vertical
        private double getValueScale(double h)
            int max = getMaxValue();
            return (h - 2*PAD) / max;
        private int getMaxValue()
            int max = Integer.MIN_VALUE;
            for(int j = 0; j < data.length; j++)
                if(data[j] > max)
                    max = data[j];
            return max;
        private String[] getLabels()
            int max = getMaxValue();
            double inc = max/3d;
            double next = max;
            String[] s = new String[4];
            for(int j = 0; j < 4; j++)
                s[j] = nf.format(next - j * inc);
            return s;
    }

  • Getting data into an applet

    I am creating an applet to draw graphs.
    I have only made standalone applets before.
    My data will come from a database.
    The user will have the data selected for them, when they select the applet page, the data to be drawn will already have been selected.
    i.e. I only need to give data across in the initialisation stage of the applet.
    What is the standard way to get data into an applet?
    By a giving a file path, by direct contact with the DB, with direct contact with another servlet or by giving the data in the HTML page the Applet is contained in.
    (The data will come from the same server as the applet)
    Maybe somone can point me to a tutorial on this?

    I am currently developing some graph applets, too. At first I implemented direct database access via JDBC, but found out, that this ain't suitable, because you can get in serious trouble with customers who don't want to open database tcp ports in their internal firewall system which - from a security point of view - is a good decision.
    So I gathered information about other methods to get data across the network. RMI needs own ports just like JDBC. Direct access to port 80 would be a good, so one could use Java's network capabilities. But this needs lots of coding on both ends (server and client-applet) and so takes time and is error prone.
    Using SOAP leads to fat applets and so I gave XML-RPC a try. In my case I have an XML-RPC server written in PHP (using the PEAR module see: http://pear.php.net ) and in my applet I use the XML-RPC library from the Apache Group (see: http://ws.apache.org/xmlrpc/ ). This works just fine!
    Pros:
    - small library code in applet (less than 200 KB)
    - only needs one network port. standard is 80 (http) which is almost everywhere available
    - applet code is independent from server code and architecture, as almost every language has some XML-RPC module (other than RMI being a Java-only solution)
    - free of charge & open source
    - reliable
    Cons:
    - based on XML it can slow down things a bit when lots of data has to be sent over a slow network link - but that's more of a general problem in network application development
    - other than SOAP/RMI you can not transmit/access whole objects but only data of primitive types (int, boolean, string, ..), so you have to wrap and unwrap your data
    By now I am very pleased with the decision I made earlier this year. :)

  • Easiest Way to draw a graph

    Hi guys,
    what is the easiest way to draw a graph in java?
    Suppose I have 2 arrays. One array contains the x-coordinates. Another array contains the respective y-coordinates.
    I do not need the graph to be smooth. Is there a API in java that allows the programmer to draw a graph simply? If not, please kindly advise what would be the easiest way to do it. I do not need the codes but just some suggestions and advice will be fine.
    Many thanks for your time and attention!!
    Regards

    setClipArea and drawPolyline <--- good ideas, however, say 'thank you' and soon please. I did this app for someone at these forums a few months back - a line graph applet with labels etc - try it;-import java.awt.*;
    public class LineGraff extends java.applet.Applet{
       double []toGraff = {6.0, -14.0, -164.0, -210.0, 108.0, 770.0,
                                1354.0, 896.0, -572.0, -1348.0, -780.0, -108.0};
       double []numsFromFile = {6.0, -14.0, -164.0, -210.0, 108.0, 770.0,
                                1354.0, 896.0, -572.0, -1348.0, -780.0, -108.0};
       int max, min, size, Hscale;
       double Vscale;
       public void init(){
          size = numsFromFile.length-1;
          java.util.Arrays.sort(numsFromFile);
          max = (int) numsFromFile[size];
          min = (int) numsFromFile[0];
          Vscale = max-min;
          Vscale = 200/Vscale;
         Hscale = Math.round(300/size);
       public void paint(Graphics g) {
          g.setFont(new Font("Arial",0,14));
          g.drawString("Example app: drawing a graph from a double array",25,18);
          g.setFont(new Font("Arial",0,10));
          g.setColor(Color.blue);
          g.fillRect(10,20,365,230);
          g.setColor(Color.cyan);
          g.drawLine(25,25,25,225);
          g.drawLine(25,140,330,140);
          g.setColor(Color.white);
          int intA = 30, intB = 0, intC = 0;
          int intD = (int) (Math.round(140 - (Vscale * toGraff[0])));
             for(int i=1; i <= size; i++) {
               intC = intA + Hscale;
               intB = intD;
               intD = (int) (Math.round(140 - (Vscale * toGraff[ i ])));
               g.drawLine(intA, intB, intC, intD);
                  if(toGraff[ i ] > 0)
                     g.drawString(Double.toString(toGraff[ i-1 ]), intA+6, intB-3);
                  else
                     g.drawString(Double.toString(toGraff[ i-1 ]), intA+6, intB+8);
               intA += Hscale;
          g.drawString(Double.toString(toGraff[size]), intA+6, intD-3);    
    }

  • Java.lang.ClassNotFoundException on Mac only

    Hello,
    I have a graphing applet that has been working quite well for a couple of years. It was build using Corda's (http://www.corda.com/) PopChart Builder v3.0 and compiled with JRE 1.2.
    In the past several months we have been having an increasing number of Mac users saying they are getting the message "java.lang.ClassNotFoundException: PopChart.class". So far, Corda's support has been non-existant.
    I'm just wondering if recompiling with JRE 1.4.1 might fix some of the problems. I suspect, but have no proof, that the Mac users are using OS X. Still trying to investigate this.
    If anyone has any experience with similar problems, I'd love to hear from you.
    Many thanks in advance,
    John Heuer
    XENERGY Inc.

    How about giving us the URL of the page with the applet?

  • Simple layout problem

    Hi,
    I am trying to make a simple graph applet, but the layout of the
    table along the x axis is giving me some problems. If you compile
    and run the following code you will see what I mean
    import java.awt.*;
    import java.applet.*;
    public class Lines2 extends Applet {
            TextField start_prompt;
            TextField stop_prompt;
            TextArea result_area;
    public void init(){
            start_prompt = new TextField();
            stop_prompt = new TextField();
            result_area = new TextArea();
            setLayout(new BorderLayout());
            Panel panel = new Panel();
            Panel panel2 = new Panel();
            panel2.setLayout(new GridLayout(1, 9));
            add(panel2, "South");
            add(panel, "West");
            panel2.add(new Label(""));
            panel2.add(new Label("Sundays"));                                         
            panel2.add(new Label("Mondays"));               
            panel2.add(new Label("Tuesdays"));       
            panel2.add(new Label("Wednesdays"));
            panel2.add(new Label("Thursdays"));
            panel2.add(new Label("Fridays"));
            panel2.add(new Label("Saturdays"));
            panel2.add(new Label(""));
    public void paint(Graphics g){
        g.drawLine(40,330,650,330);
        g.drawLine(40,330,40,40); 
    }The problem is that "Wednesdays" and "Thursdays" are smushed
    together as you can see. I need a way to widen the gap between them.
    I tried adding a blank Label but that made the gap to large. Anybody
    have any ideas that would help me?
    Thks....

    How about panel2.setLayout(new GridLayout(1, 9, 5, 0))?

  • Detect JRE Version

    I have an applet up and working but it needs the java.policy file get modified in order to do some of it's stuff. Is there a way to do that thru code? Like asking for permission to the user in order to change the permissions there?
    Any idea?

    A should digitially "sign" your applet's jar file
    instead.
    This will then present the user with a dialog box
    asking if they wish to trust the content downloaded
    and signed by "javydreamersw" or whatever name you
    wish to use.
    Ps. digitially signing jars should be well
    documented, and asked very frequently.
    You should have no trouble finding out how to do it.
    regards,
    OwenThat's a good idea but I can't freely sign jar's on jre 1.5. I was able to create the certificate but I can't sign the jar and I'm 300% sure that my company won't pay $400/year for a small graphing applet.
    I know there was a jarsigner in earlier jdk's but got eliminated for v 1.5 and seems like the only way around it is thru companies.
    Any idea?

  • Devloping graphs using pure java without applets and swings

    Hi Guys
    i want to devlop bar graphs,pie charts,line graphs using pure java.i don't want to use applets and swings..does any body help on this asap..
    IT'S VERY URGENT
    cheers
    ANAND

    Go to
    http://java.sun.com/docs/books/tutorial/information/download.html#OLDui
    and get: Creating a User Interface (AWT Only) Archive (tut-OLDui.zip)

  • How do i draw a graph in a applet from ny data

    Hi, again sorry to keep coming back to you guys, but i have been trying hard to attempt things myself.I have read loads of books and can not find example to work from.I have managed with your "help" to finnish my calculations. Now i need to plot a graph with the data from my X array and Y array. I will then try my self to plot the linear least fit line if it kills me. I would like to print stars on the graph using the points in my arrays. But where do i start
    sorry if i am asking to much i will understand if you can't help as you have really good programers asking proper questions instead of a novice like me.i have tried but get errors
    LinearLeast1.java:111: illegal start of expression
    public void paint (Graphics gr)
    ^
    LinearLeast1.java:120: ';' expected
    ^
    LinearLeast1.java:3: cannot resolve symbol
    symbol : class Applet
    location: class LinearLeast1
    class LinearLeast1 extends Applet
    ^
    3 errors
    lindsey
    code:
    import java.io.*;
    class LinearLeast1 extends Applet
    { // start of new class
    //defines the sum method
              public static double SumA (double arr[])
              double SumA =0; //sum of array
              if (arr.length >=1)
                   for(int i=0; i< arr.length; i++)
                        SumA +=arr;
              else
                   SumA =0; // insuficient data
                   return SumA;
              // defines the sum of XY array method
              public static double sumXY (double arrX[],double arrY[])
                   double SumXY=0; // sum of arrays X*Y
                   if(arrX.length>=2)
                        for(int i=0; i< arrX.length;i++)
                             SumXY +=arrX[i]*arrY[i];
                   else
                        SumXY=0;//insufficient data
                   return SumXY;
              //defines the avarage method
              public static double AverageB (double arr[])
              double SumA =0; //sum of array
              double AverageB =0; // average of array
              if (arr.length >=1)
                   for(int i=0; i< arr.length; i++)
                        SumA +=arr[i];
                   AverageB = SumA / arr.length;
              else
                   AverageB =0; // insuficient data
                   return AverageB;
              //defines array to the power of 2 method
              public static double SumB (double arr[])
              double SumB = 0; // sum of squares of array
              double SumA =0; //sum of array
              double Square =0; // array to the power of 2
              if (arr.length >=2)
                   for(int i=0; i< arr.length; i++)
                        SumA +=arr[i];
                        SumB += arr[i] * arr[i];     
                   Square =Math.sqrt((arr.length* SumB - SumA*SumA) / (arr.length*(arr.length-1)));
              else
                   Square =0; // insuficient data
                   return SumB;
                   public static void main(String[]args)
         { //start of main method
                                       //values for array x
              double [] arrX ={-4.91,-3.84,-2.41,-2.62,-3.78,-0.52,-1.83,-2.01,0.28,1.08,
              -0.94,0.59,0.69,3.04,1.01,3.60,4.53,5.13,4.43,4.12};
              // values for array y
              double [] arrY ={-8.18,-7.49,-7.11,-6.15,-5.62,-3.30,-2.05,-2.83,-1.16,0.52,
              0.21,1.73,3.96,4.26,5.75,6.67,7.70,7.31,9.05,10.05};
         double SumXY = sumXY(arrX,arrY);
    double m = (SumXY-(SumA(arrX)*AverageB(arrY)))/ (SumB(arrX)-(SumA(arrX)*AverageB(arrX)));
    double B = LinearLeast1.AverageB(arrY)-m*LinearLeast1.AverageB(arrX);
    // System.out.println(" m = "+ m );
    // System.out.println(" array X * array Y = "+LinearLeast1.sumXY(arrX,arrY));
         // System.out.println(" sum ofarray x "+ LinearLeast1.SumA(arrX));
         // System.out.println(" sum ofarray y "+ LinearLeast1.SumA(arrY));
         // System.out.println(" avarage of array x " + LinearLeast1.AverageB(arrX));
         // System.out.println(" avarage of array y " + LinearLeast1.AverageB(arrY));
         // System.out.println(" power of 2 array x " + LinearLeast1.SumB(arrX));
         // System.out.println(" m= "+m);
         // System.out.println(" B= "+B);
    public void paint (Graphics gr)
         for(int i=1; i< arr.length; i++)
    g.drawLine((i-1)*arrXSCALING, arr[i-1]*YSCALING,
    i*XSCALING, arr[i]*YSCALING);
    }//end of paint method
    } //end of main method
    } // end of class

    Thanks for that, I thought I upset every one, only just stopped crying
    here is my ammended code again before I go to bed, hope it's right this time
    import java.io.*;
    class LinearLeast1 extends Applet
    { // start of new class
                 //defines the sum method
                   public static double SumA (double arr[])
                  double SumA =0;      //sum of array
                  if (arr.length >=1)
                         for(int K=0; K< arr.length; K++)
                              SumA +=arr[K];
                      else 
                           SumA =0; // insuficient data
                           return SumA;
                  // defines the sum of XY array method
                  public static double sumXY (double arrX[],double arrY[])
                       double SumXY=0; // sum of arrays X*Y
                        if(arrX.length>=2)
                              for(int K=0; K< arrX.length;K++)
                                   SumXY +=arrX[K]*arrY[K];
                        else
                               SumXY=0;//insufficient data
                          return SumXY;
                  //defines the avarage method
                   public static double AverageB (double arr[])
                  double SumA =0;      //sum of array
                  double AverageB =0;  // average of array
                  if (arr.length >=1)
                         for(int K=0; K< arr.length; K++)
                              SumA +=arr[K];
                         AverageB = SumA / arr.length;
                     else 
                           AverageB =0; // insuficient data
                           return AverageB;
                    //defines array to the power of 2 method
                   public static double SumB (double arr[])
                  double SumB = 0;     // sum of squares of array
                  double SumA =0;      //sum of array
                  double Square =0;  // array to the power of 2
                  if (arr.length >=2)
                         for(int K=0; K< arr.length; K++)
                              SumA +=arr[K];
                              SumB += arr[K] * arr[K];     
                         Square =Math.sqrt((arr.length* SumB - SumA*SumA) / (arr.length*(arr.length-1)));
                     else
                           Square =0; // insuficient data
                           return SumB;
                    public static void main(String[]args)
         { //start of main method
                                       //values for array x
              double [] arrX ={-4.91,-3.84,-2.41,-2.62,-3.78,-0.52,-1.83,-2.01,0.28,1.08,
                             -0.94,0.59,0.69,3.04,1.01,3.60,4.53,5.13,4.43,4.12};
                                 // values for array y
              double [] arrY ={-8.18,-7.49,-7.11,-6.15,-5.62,-3.30,-2.05,-2.83,-1.16,0.52,
                                0.21,1.73,3.96,4.26,5.75,6.67,7.70,7.31,9.05,10.05};
            double SumXY = sumXY(arrX,arrY);
           double m = (SumXY-(SumA(arrX)*AverageB(arrY)))/ (SumB(arrX)-(SumA(arrX)*AverageB(arrX)));
          double B = LinearLeast1.AverageB(arrY)-m*LinearLeast1.AverageB(arrX);
       public void paint (Graphics gr)
          for(int K=1; K< arr.length; K++)
        g.drawLine((K-1)*arrXSCALING, arr[K-1]*YSCALING,
        K*XSCALING, arr[K]*YSCALING);
          }//end of paint method
       } //end of main method
    } // end of classHope that is better, I will take your advise and not give up. Will try to have another go tomorrow as it is 2.30am now. So I will try and get some sleep. Thanks again for coming back to answer I needed that bit of encouragement. Don't know if that bit of code for drawing my applet is right or not.
    good night and thanks again
    Lindsey

  • Create the graph using java applet

    Hi friends,
    I have one urgent requirement.I need to create the flowchart by using java code.I have data in database.based on that i need to create the parent child relationchip graph..plase anybody help me .
    Thanks&Regards,
    Yousuf alam.A

    malcolmmc wrote:
    JFreeChart has been the favourite Java graph drawing library but, last time I looked, it didn't do flowcharts. If I were you I'd fire up Google and hunt around for a 3rd party library that does. Of course it's a pain if you have to use such libraries in an Applet. It's generally better to generate an image file on a server and display it as part of your html page.Sorry Malcolm but I don't think JFreeChart is applicable. The OP is asking for Flowcharts which are a graph as in nodes and edges. JGraph (Google) is probably what the OP wants but he is in for a shock when it comes to using it.

  • Plotting an X,Y graph in a Java Applet

    Hi,
    I am starting to get into Java as much as possible, and love the command prompt programming, but am stilly pretty stuck with the Applet side of things :( Anyway, I have done this code so far:
    http://www.hashjava.com/codeboard.php?user=1
    However, I need to implement an X,Y graph in an applet - I have no idea really how to do this. I have looked at using class Point2D.Double, but I don't know what to do really.
    The graph must be plotted from the points contained in the two arrays xValue / yValue (lines 27 and 28 respectively). If someone could point me in the right direction, that would be great. The graph just needs to be plotted from this array - no user interface is needed apart from the user being able to see the graph with lines drawn between successive the points...
    Any help would be greatly appreciated,
    Kind Regards,
    Alex

    Hi,
    I have drawn a graph on a JPanel which runs as part of a GUI written in Swing. But the code I wrote was laboured and uses mostly java.awt drawing APIs. Can you let me know if found something more advanced for drawing graphs as I couldn't find anything.
    regards,
    MG.

  • Write n then read xml from database to create graph in an applet

    Hi mates
    I have one problem I want show a trend(graph) from sql database which is having the records of about 8600 in a day. And i want to show a graph for a day
    but sometimes it gives a problem like out-of-memory, so can anyone tell me how i can get read of it.
    and other this can i use xml for this means first write a data in xml format from database then read it at sametime and show graph in applet
    can anytell me how to do it
    any suggesion is appreciable
    thanx

    Here's are two example for what you are looking for
    Re: Load xml data in Oracle table
    Re: insert .xml file into xmltype table?
    First you need to create a DIRECTORY object.  That is how Oracle works and it expects a DIRECTORY object instead of a physical path when performing operations that read/write from disk.  The directory path provided to the CREATE DIRECTORY command must be a directory that the machine Oracle DB resides on can see.
    Then you can go either of two routes.  You can INSERT that XML directly into a table, as shown in the second link I provided or you can read it into PL/SQL as the first link shows.  Then in either case, you can use SQL to parse the XML for you.
    Depending upon your needs, you may get better performance if you insert the XML into a table as the second link shows, assuming the XMLType column is stored as SECUREFILE BINARY XML.

Maybe you are looking for