hi,
i m trying to draw a piechart using bufferedimage class using the following code
response.setContentType("image/png");
String[] slices = request.getParameterValues("slice");
String[] colors = request.getParameterValues("color");
int[] sizes = new int[slices.length];
Color[] cols = new Color[slices.length];
for(int i=0; i<slices.length; i++) {
sizes[i] = Integer.parseInt(slices[i]);
cols[i] = new Color(Integer.parseInt(colors[i],16));
}
try{
int width = Integer.parseInt(request.getParameter("width"));
int height = Integer.parseInt(request.getParameter("height"));
Color background = new Color(Integer.parseInt(request.getParameter("background"),16));
BufferedImage buffer =new BufferedImage (width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = buffer.createGraphics();
g2.setColor(background);
g2.fillRect(0,0,width,height);
int arc = 0;
for(int i=0; i<sizes.length; i++) {
g2.setColor(cols[i]);
g2.fillArc(0,0,width,height,arc,sizes[i]);
arc += sizes[i];
}
ServletOutputStream os = response.getOutputStream();
boolean flag=ImageIO.write(buffer, "png", os);
}
catch (Exception e){
}
it gives following error at run time
javax.servlet.ServletException:
Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain............................................................................................................
root cause
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
at pie.doGet(pie.java:53)...........................................................
can any body pls indicate what may b wrong.
also if i comment the buffer.createGraphics code an image opens in photo shop showing a black rectangle.
looking forward for some help
regards
khushi