I'm trying to generate graphs dynamically using JFreeChart as a result of some checkboxes the user selects, but I can't figure out how best to get the generated datasets into chart form (I have code that makes charts from these, but need to produce pngs) and into the JSP view. Currently, I can only think of sending the Datasets to the JSP, but can't think of what to do from there... How do I make it so that: user submits form to servlet, servlet generates datasets, charts produced from datasets, pngs from charts and finally pngs dispatched to jsp? Or something along those lines.
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException{
String[] metrics = request.getParameterValues("metrics");
String[] fileNames = request.getParameterValues("files");
List<CategoryDataset> results = new ArrayList<CategoryDataset>();
DMCalc calculator = new DMCalc(metrics, fileNames);
calculator.calculateResults();
results.add(calculator.getEditDistanceDataset());
results.add(calculator.getSimilarityDataset());
results.add(calculator.getTimeChartDataset());
request.setAttribute("results", results);
RequestDispatcher view = request.getRequestDispatcher("metricResult.jsp");
view.forward(request, response);
}
UPDATE:
By having the doPost method generate the datasets from the user post, they can then be stored in fields, subsequently the RequestDispatcher forwards the user to the JSP which then calls the servlet's doGet method in an img tag, which uses the datasets stored earlier in the fields to produce a png and that is then displayed by the HTML in the JSP.