3
Hello! I’m looking to generate graph by jsp
I tried to follow that tutorial
But only a little square appears in the left corner of the page when I run
Filing cabinet Torta.jsp
<%
try{
DefaultPieDataset data = new DefaultPieDataset();
while(rs.next()){
data.setValue(rs.getString("marca"), rs.getInt("TOTAL"));
}
JFreeChart grafico = ChartFactory.createPieChart("Cantidad Productos", data, true, true, true);
response.setContentType("image/JPEG");
OutputStream sa = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(sa, grafico, 600,600 );
}
catch(Exception ex){
}
%>
Filing cabinet conexion.jsp
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/producto","root","123");
Statement cmd= cn.createStatement();
String sql = "SELECT MARCA, SUM(CANTIDAD) AS TOTAL FROM PRODUCTO_CANTIDAD GROUP BY MARCA";
ResultSet rs = cmd.executeQuery(sql);
%>
Screenshot of how the chart appears:
Thank you in advance.
– adventistaam
1How are you referencing this image on the page? The Code is only this 2. Have you tried running this query in the database to see if it returns data? Yes. Returns data 3. Tried to put an ex.printStackTrace() in the catch to see if there is no error in the execution? I will try now
– adventistaam
on the Chrome console it appears like this: net::ERR_INCOMPLETE_CHUNKED_ENCODING
– adventistaam
Try to close Outputstream ( sa.close() ), if it does not work, call the flush before closing ( sa.flush() )... It seems that the browser does not receive the end of the file...
– Eldius
That’s it! It worked with sa.close(); !
– adventistaam
That’s right! It was right! That’s right! I added sa.close(); and it worked. Thank you very much!
– adventistaam