Example usage for org.jfree.eastwood ChartEngine buildChart

List of usage examples for org.jfree.eastwood ChartEngine buildChart

Introduction

In this page you can find the example usage for org.jfree.eastwood ChartEngine buildChart.

Prototype

public static JFreeChart buildChart(Map params, Font font) 

Source Link

Document

Creates and returns a new <code>JFreeChart</code> instance that reflects the specified parameters (which should be equivalent to a parameter map returned by HttpServletRequest.getParameterMap() for a valid URI for the Google Chart API.

Usage

From source file:org.jfree.eastwood.ChartApplet.java

/**
 * Starts the applet./* w  w  w.  java  2  s. c  o m*/
 */
public void start() {
    String chartSpec = getParameter("chart");
    try {
        Map params = Parameters.parseQueryString(chartSpec);
        JFreeChart chart = ChartEngine.buildChart(params, new Font("Dialog", Font.PLAIN, 12));
        this.chartPanel.setChart(chart);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

From source file:org.jfree.eastwood.ChartServlet.java

/**
 * Process a GET request./*www  .j  ava2  s .  c o  m*/
 *
 * @param request  the request.
 * @param response  the response.
 *
 * @throws ServletException if there is a servlet related problem.
 * @throws IOException if there is an I/O problem.
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    OutputStream out = response.getOutputStream();

    try {
        Map params = Parameters.parseQueryString(request.getQueryString());
        JFreeChart chart = ChartEngine.buildChart(params, this.font);

        if (chart != null) {
            response.setContentType("image/png");

            // *** CHART SIZE ***
            String[] size = (String[]) params.get("chs");
            int[] dims = new int[2];
            if (size != null) {
                dims = parseChartDimensions(size[0]);
            } else {
                dims = new int[] { 200, 125 };
            }

            ChartUtilities.writeChartAsPNG(out, chart, dims[0], dims[1]);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        out.close();
    }

}