drawPolyLine

From: Taji (gabsaga_tata_at_hotmail.com)
Date: 10/01/04


Date: 1 Oct 2004 11:25:58 -0700

Does anyone have a servlet that draws a poly-line graph that I can
use? I have one but it draws the graph with the origin at the top left
corner of the image object. I just need to know how to translate the
graph so that the origin is at the bottom left corner so it looks like
a normal graph with x and y coordinates. Any help will be appreciated.
Thanks. Gabsaga

// servlet imports
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// image imports
import java.awt.* ;
import java.awt.image.* ;
import javax.swing.*;
import java.awt.geom.*;
import com.sun.image.codec.jpeg.*;

public class PlotPoints extends HttpServlet {

/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}

/**Process the HTTP Post request*/
public void service(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {

int xCoords[] = {0,10,200,300,400};
int yCoords[] = {0,10,100,200,0};
int numOfPoints = xCoords.length;

BufferedImage img = new BufferedImage
(200,200,BufferedImage.TYPE_3BYTE_BGR);

Graphics g = img.getGraphics();

Font font = Font.getFont("Dialog");

g.setFont(font);
g.setColor(Color.white);
//g.translate(200 / 20, 200 - 200 / 20); // <---- I tried this but it
didn't work
g.drawPolyline(xCoords, yCoords, numOfPoints);

response.setContentType("image/gif");

ServletOutputStream out = response.getOutputStream();

JPEGImageEncoder jenc = JPEGCodec.createJPEGEncoder(out);
jenc.encode(img);

out.flush();
out.close();
}
} //end of doService



Relevant Pages

  • Re: how does the Model (Command), in MVC, return objects to a servlet?
    ... Command command = lookupCommand; Result result = ... command.execute(request); ... The Base Enterprise Servlet from which all Enterprise Servlet ... public void service ...
    (comp.lang.java.help)
  • applet to servlet
    ... I'm trying to send an object to a servlet for processing. ... getting an EOFException or NullPointerException at the readObject() method ... public void doPost(HttpServletRequest request, ... class TableData implements Serializable ...
    (comp.lang.java.help)
  • Re: Im getting frustrated and angry!
    ... problem with it thats causing the servlet not to create the file ... public void SendData() ... public class receiver extends HttpServlet ...
    (comp.lang.java.help)
  • cactus and servlet redirection
    ... testPostMethodof testcase merely creates a BookAddServlet and calls ... I am using endPostMethod(com.meterware.httpunit.WebResponse response) ... Is this because the doGetof BookList servlet is invoked in between? ... public void doPost(HttpServletRequest request, HttpServletResponse ...
    (comp.lang.java.programmer)
  • Any suggestions of doing refreshing data in a web module?
    ... static TreeMap<Long, String> map; ... Initialization of the servlet. ... public void init() throws ServletException { ... } catch (IOException e) { ...
    (comp.lang.java.programmer)