From: Nathaniel G. A. <nat...@ya...> - 2002-11-25 13:21:12
|
hey Srini Is there a reason you want to write the image to a file? This is will be a liability when you try to scale your app. Why do you want a single request to the server and not use two requests? Also, looking at your code, i dont think it is thread-safe. There is a possibility for the counter on the file name to not get incremented and have another thread use the same counter. you would have to synchronize the creation of the file name and increment of the counter. This will be a performance liability too. just my two cents. --- Srini <sr...@le...> wrote: > Following is the code, I added at the end of my servlet which creates the imagemap of an > axischart for a bar chart. This code generates the imagemap and sends it to the browser. Since > the jpg file is created everytime, when the servlet is called, it has to deleted periodically. > This method is used to have all the logic(chart creation and imagemap creation) for the chart > in a single servlet. Any suggestion is appreciated.This servlet works fine. > > Steps: > > axixchart is created first (this is not shown here) > Save axischart to jpg file. File name is generated using a counter. > created <IMG> tag with the newly created jpg file > Generate SCRIPT commands for display of the data value with the labels > Generate the html for imagemap > > //------------------------------------------------------------------------- > // Save the generated axischart into jpg file > //------------------------------------------------------------------------- > > String filefile="chart_"+imgcntr+".jpg"; > //-------------------------------------------------------------------------------------- > try > { > > String filex = getServletContext().getRealPath(filefile); > FileOutputStream fos = new FileOutputStream(filex); > JPEGEncoder13.encode( axisChart, 1.0f, fos); > fos.close(); > fos.flush(); > } > catch( IOException ioException ) > { > ioException.printStackTrace(); > } > //------------------------------------------------------------------------- > // create a chart object and get the imagemap for the chart > //------------------------------------------------------------------------- > > > String IMAGE_MAP= "IMAGE_MAP"; > Chart chart= null; > > > try > > > { > > > chart= (Chart) axisChart; > > > } > > > catch( Exception chartDataException ) > > > { > > > chartDataException.printStackTrace(); > > > } > > > > > > //---this call will render the chart to an internal BufferedImage, creating all the image map > coordinates > > chart.renderWithImageMap(); > > > > > > //---get the ImageMap information from the chart > > > ImageMap imageMap= chart.getImageMap(); > > > > > > //---set the ImageMap into the HttpServletRequest so can get it out in JSP > > > //request.setAttribute( IMAGE_MAP, imageMap ); > > > > > > > Iterator iterator= imageMap.getIterator(); > > > //------------------------------------------------------------------------- > // generate the SCRIPT function to display the values > //------------------------------------------------------------------------- > > > StringBuffer html= new StringBuffer( 400 ); > > > out.println("<script language=\"JavaScript\">"); > > > out.println("function showValues( value, legendLabel, xAxisLabel ){"); > > > out.println("if( xAxisLabel != 'null' ){"); > > > out.println("alert( \"Value= \" + value + \" \\nLegend label= \" + legendLabel + \"\\nAxis > label= \" + xAxisLabel );}"); > > out.println(" else {alert( \"Value= \" + value + \"\\nLegend label= \" + legendLabel > );}}"); > > out.println("</script>"); > > > //------------------------------------------------------------------------- > // output imagemap html contetnts > //------------------------------------------------------------------------- > > > > > out.println("<img border=\"0\" src="+filefile+" useMap=\"#chartMap\">"); > > > out.println("<map name=\"chartMap\">"); > > > while( iterator.hasNext() ) > > > { > > > ImageMapArea imageMapArea= (ImageMapArea) iterator.next(); > > > String hml=imageMapArea.toHTML( html.toString() ); > > > int ll = hml.length(); > > > out.println(hml.substring(0,ll-1)); > > > html.append( "href=\"javascript:showValues(" ); > > > html.append( imageMapArea.getValue() ); > > > html.append( ",'" ); > > > html.append( imageMapArea.getLengendLabel() ); > > > html.append( "','" ); > > > html.append( imageMapArea.getXAxisLabel() ); > > > html.append( "');\">" ); > > > out.println(html.toString()); > > > html.delete( 0, html.length() ); > > > } > > > html.append("</map>"); > > > out.println(html.toString()); > > ===== An easy read on your Digital Rights Disappearing [http://newsforge.com/newsforge/02/10/21/1449250.shtml?tid=19] __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus Powerful. Affordable. Sign up now. http://mailplus.yahoo.com |