Example usage for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection

List of usage examples for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection

Introduction

In this page you can find the example usage for org.jfree.chart.entity StandardEntityCollection StandardEntityCollection.

Prototype

public StandardEntityCollection() 

Source Link

Document

Constructs a new entity collection (initially empty).

Usage

From source file:org.n52.server.service.GetImageService.java

private ImageDataResult performChartRendering(DesignOptions options) {
    try {//  w ww . ja  v a 2 s . c o m
        EESGenerator chartGenerator = new EESGenerator();
        ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
        String chartUrl = chartGenerator.createChart(options, renderingInfo);
        return new ImageDataResult(chartUrl);
    } catch (Exception e) {
        LOGGER.error("Could not render time series chart.", e);
        throw new InternalServiceException();
    }
}

From source file:utils.Graphs.java

public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) {
    DefaultPieDataset dataset = new DefaultPieDataset();

    // add our data values
    int i = -1;// w w  w.  ja  va 2  s .  c  o m
    for (String title : titles) {
        i++;
        dataset.setValue(title, values[i]);
    }

    final JFreeChart chart =
            //                ChartFactory.createPieChart("", dataset, true, true, false);

            ChartFactory.createPieChart("", // chart title
                    dataset, // data
                    true, // include legend
                    true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    //PiePlot3D plot = (PiePlot3D) chart.getPlot();
    //plot.setStartAngle(290);
    plot.setStartAngle(45);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);

    //        final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(backgroundColor);

    //        plot.setLegendLabelGenerator(
    //        new StandardPieSectionLabelGenerator("{0} {2}"));

    chart.setBorderVisible(false);
    chart.getPlot().setOutlineVisible(false);
    chart.getLegend().setFrame(BlockBorder.NONE);

    // get the same background
    chart.setBackgroundPaint(backgroundColor);
    chart.getLegend().setBackgroundPaint(backgroundColor);

    // hide the shadow effects
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //chart.getLegend().setVisible(false);

    plot.setCircular(true);
    //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data found.");

    Color greenColor = new Color(0x8FBC0C);
    Color redColor = new Color(0xFF0000);
    //Color redColor = new Color(0xDA6022);

    plot.setSectionPaint(0, greenColor);
    plot.setSectionPaint(1, redColor);
    plot.setSectionOutlinesVisible(true);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file = new File(baseFolder, "chart.png");
    try {
        ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info);
    } catch (IOException ex) {
        Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex);
    }
    //        
    ////        final ChartPanel chartPanel = new ChartPanel(chart, true);
    //       final ChartPanel chartPanel = new ChartPanel(chart, true);
    //        chartPanel.setMinimumDrawWidth(0);
    //        chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    //        chartPanel.setMinimumDrawHeight(0);
    //        chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    //        JDialog dialog = new JDialog();
    //        dialog.add(chartPanel);
    //        dialog.setLayout(new GridLayout(1, 1));
    //        dialog.setSize(400, 200);
    //        dialog.setVisible(true);

    return file;
}

From source file:servlet.SalesReportEventsBarChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w w  .j a  va2  s . c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<ArrayList> data = productSession.getEventSessionNo();

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < data.size(); i++) {
        dataset.addValue(Integer.valueOf(data.get(i).get(1).toString()), "Sessions",
                data.get(i).get(0).toString());
    }

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    JFreeChart barChart = ChartFactory.createBarChart("No of Sessions", "Event", "Sessions", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot cplot = (CategoryPlot) barChart.getPlot();
    cplot.setBackgroundPaint(Color.WHITE);//change background color

    //set  bar chart color
    ((BarRenderer) cplot.getRenderer()).setBarPainter(new StandardBarPainter());

    BarRenderer r = (BarRenderer) barChart.getCategoryPlot().getRenderer();
    r.setSeriesPaint(0, Color.GREEN);

    r.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
    r.setBaseItemLabelsVisible(true);

    CategoryAxis categoryAxis = cplot.getDomainAxis();
    categoryAxis.setUpperMargin(0.15);

    NumberAxis rangeAxis = (NumberAxis) cplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    int width = 550; /* Width of the image */

    int height = 450; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, barChart, 400, 300, info);

}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Return rendering information for the chart.
 *//*  w ww  .  j ava  2 s .  c  om*/
public static final ChartRenderingInfo getMetricRenderingInfo() {
    return new ChartRenderingInfo(new StandardEntityCollection());
}

From source file:gda.plots.SimpleLegendLabelBlock.java

/**
 * Overrides super class method to provide a BlockResult which contains a SimpleLegendEntity instead of an ordinary
 * ChartEntity.//w ww . j  ava  2 s.com
 * 
 * @param g2
 *            the Graphics to use
 * @param area
 *            the area to draw in
 * @param params
 *            ignored
 * @return a BlockResult containing the SimpleLegendEntity
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    // It was impossible to reuse the super class code because of
    // private fields with no accessor methods. So run the method
    // then replace the EntityCollection with one containing a
    // SimpleLegendEntity. The super class method may return null
    // (e.g. when being drawn for printing). If it does then we
    // should too.
    BlockResult result = (BlockResult) super.draw(g2, area, params);
    if (result != null) {
        StandardEntityCollection sec = new StandardEntityCollection();
        ChartEntity ce = result.getEntityCollection().getEntity(0);
        sec.add(new SimpleLegendEntity(ce, sxys));
        result.setEntityCollection(sec);
    }
    return result;
}

From source file:com.glaf.chart.util.ChartUtils.java

public static void createChart(String path, Chart chartModel, JFreeChart chart) {
    try {//w ww .j  a v  a 2  s .  com
        java.awt.image.BufferedImage bi = chart.createBufferedImage(chartModel.getChartWidth(),
                chartModel.getChartHeight());

        String name = chartModel.getChartName();
        if (StringUtils.isNotEmpty(chartModel.getMapping())) {
            name = chartModel.getMapping();
        }

        if ("png".equalsIgnoreCase(chartModel.getImageType())) {
            EncoderUtil.writeBufferedImage(bi, chartModel.getImageType(),
                    new FileOutputStream(path + "/" + name + ".png"));
            ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            ServletUtilities.saveChartAsPNG(chart, chartModel.getChartWidth(), chartModel.getChartHeight(),
                    info, null);
        } else if ("jpeg".equalsIgnoreCase(chartModel.getImageType())) {
            EncoderUtil.writeBufferedImage(bi, chartModel.getImageType(),
                    new FileOutputStream(path + "/" + name + ".jpg"));
            ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
            ServletUtilities.saveChartAsJPEG(chart, chartModel.getChartWidth(), chartModel.getChartHeight(),
                    info, null);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}

From source file:org.n52.series.api.proxy.v0.srv.GetImageService.java

private ImageDataResult performChartRendering(DesignOptions options) {
    try {/*w  w w .j a va  2  s  .c o m*/
        EESGenerator chartGenerator = new EESGenerator();
        ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
        String chartUrl = chartGenerator.createChart(options, renderingInfo);
        return new ImageDataResult(chartUrl);
    } catch (Exception e) {
        LOGGER.error("Could not render time series chart.", e);
        throw new InternalServerException("internal error!", e);
    }
}

From source file:servlet.SalesReportPieChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww  w.  j ava2 s. c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    DefaultPieDataset dataset = new DefaultPieDataset();
    int totalTickets = Integer.valueOf(request.getParameter("totalTickets"));
    int totalSoldTickets = Integer.valueOf(request.getParameter("totalSoldTickets"));

    dataset.setValue("Unsold Tickets", new Double(totalTickets - totalSoldTickets));
    dataset.setValue("Sold Tickets", new Double(totalSoldTickets));

    JFreeChart chart = ChartFactory.createPieChart("Ticket Sales", // chart title
            dataset, // data
            true, // include legend
            true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Unsold Tickets", Color.DARK_GRAY);
    plot.setSectionPaint("Sold Tickets", Color.CYAN);
    plot.setExplodePercent("Unsold Tickets", 0.10);
    plot.setSimpleLabels(true);
    plot.setBackgroundPaint(Color.WHITE);

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    int width = 500; /* Width of the image */

    int height = 400; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, chart, 400, 300, info);
}

From source file:gda.plots.SimpleLegendGraphic.java

/**
 * Overrides the super class method but is the same except that it creates a SimpleLegendEntity for itself and then
 * returns a non-null BlockResult containing the entity.
 * /*  ww w.j  a  v  a2 s  . co  m*/
 * @param g2
 *            the Graphics2D to use
 * @param area
 *            the area to draw in
 * @param params
 *            ignored
 * @return a BlockResult containing a StandardEntityCollection containing the SimpleLegendEntity
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {

    draw(g2, area);

    ChartEntity entity = null;
    // This was written by looking at what happens in LabelBlock's draw
    // method. The area has to be transformed into the actual coordinates
    // of the overall ChartPanel for the MouseEvents to work properly.
    entity = new SimpleLegendEntity(g2.getTransform().createTransformedShape(area), sxys.getName(), null, sxys);

    BlockResult result = new BlockResult();
    StandardEntityCollection sec = new StandardEntityCollection();
    sec.add(entity);
    result.setEntityCollection(sec);
    return result;
}

From source file:de.laures.cewolf.util.Renderer.java

/**
 * Renders a chart//from   w  w w . j  a va  2  s  . c  o m
 * @param cd the chart image to be rendered
 * @return the rendered image
 * @throws CewolfException
 */
private static RenderedImage renderChart(ChartImage cd, Object chart) throws CewolfException {
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final String mimeType = cd.getMimeType();
        if (MIME_PNG.equals(mimeType)) {
            handlePNG(baos, (JFreeChart) chart, cd.getWidth(), cd.getHeight(), info);
        } else if (MIME_JPEG.equals(mimeType)) {
            handleJPEG(baos, (JFreeChart) chart, cd.getWidth(), cd.getHeight(), info);
        } else if (MIME_SVG.equals(mimeType)) {
            handleSVG(baos, (JFreeChart) chart, cd.getWidth(), cd.getHeight());
        } else {
            throw new RenderingException("Mime type " + mimeType + " is unsupported.");
        }
        baos.close();
        return new RenderedImage(baos.toByteArray(), mimeType, info);
    } catch (IOException ioe) {
        log.error(ioe);
        throw new ChartRenderingException(ioe.getMessage(), ioe);
    }
}