проблема с отображением диаграммы png на сервере jfreechart - PullRequest
0 голосов
/ 29 апреля 2020

У меня проблема с круговой диаграммой ... код не показывает диаграмму, изображение создано, но не отображается на сервере. Я пытаюсь сделать что-то в этом коде с 1 месяца, я студент, и я не знаю, что делать сейчас

    public class PieChartDemo extends HttpServlet {

private static final long serialVersionUID = 1L;
public PieChartDemo() {

} 
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    Connection connection = null;
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
        try {
            connection=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=&useUnicode=true&characterEncoding=utf-8");
        }catch (SQLException e) {
            e.printStackTrace();
        }
    }catch (InstantiationException e) {
        e.printStackTrace();
    }catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    JDBCPieDataset dataset = new JDBCPieDataset(connection);
    try {
        dataset.executeQuery("SELECT country,revenue from country_revenue order by revenue desc");
        JFreeChart chart = ChartFactory.createPieChart("Country - Revenue Chart", dataset, true, true, false);
        chart.setBorderPaint(Color.black);
        chart.setBorderStroke(new BasicStroke(10.0f));  
        chart.setBorderVisible(true);
        if (chart != null) {
            int width = 500;    
            int height = 350;
            final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            response.setContentType("image/png");
            OutputStream out=response.getOutputStream();
            ChartUtilities.writeChartAsPNG(out, chart, width, height,info);
        }
    }catch (SQLException e) {
    e.printStackTrace();
    }
} 
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}

, то есть основной код, вот проблема, я имею в виду

Screenshot

...