2uzhan.com
Advertisement
Now Place:2uzhan.com » how to draw a graph in a JSP

how to draw a graph in a JSP

Java Programming @ March 18, 2003   Views:0

i want to draw a graph(curve) with within two axes(X and Y) in a JSP.

If anybody knows a easy way to do it please advice me.
Thanx.
Best Regards,
Pradeepika

--------------Solutions-------------

Well, JSP is basically HTML with Java Language behind it. Actually it is more like a Servlet done as a static HTML page with dynamic content. You might be able to accomplish this using a Custom Tag, but it would take a lot of work. I think your best bet would be to create an Applet and place that on your JSP page.

If you choose the Applet approach, you could try something like this in the paint method.

Code:

public void paint(Graphics g)   {
   int a = 1, b = 2, c = 3, d = 4;
   for (int x=1; x < 5; x++)
      g.drawLine(x, (Math.pow(a*x, 3) + Math.pow(b*x, 2) + c*x + d), (Math.pow(a*(x + 1), 3) + Math.pow(b*(x + 1), 2) + c*(x + 1) + d));

}

Or

Code:

public void paint(Graphics g)   {
   int firstY, y1, y2, x=1;
   int a = 1, b = 2, c = 3, d = 4;

   firstY = (Math.pow(a*x, 3) + Math.pow(b*x, 2) + c*x + d;
   y1 = firstY;

   do   {
      y2 = Math.pow(a*(x + 1), 3) + Math.pow(b*(x + 1), 2) + c*(x + 1) + d;
      g.drawLine(x, y1, x + 1, y2);
      x++;
      y1 = y2;
   } while(y1 != firstY);
}

the equation I used was ax^3 + bx^2 + cx + d

Tags:
© 2018 2uzhan.com Contact