Example usage for org.jfree.chart ChartRenderingInfo ChartRenderingInfo

List of usage examples for org.jfree.chart ChartRenderingInfo ChartRenderingInfo

Introduction

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

Prototype

public ChartRenderingInfo(EntityCollection entities) 

Source Link

Document

Constructs a new instance.

Usage

From source file:org.pentaho.chart.plugin.jfreechart.outputs.JFreeChartOutput.java

public OutputStream persistChart(OutputStream outputStream, IOutput.OutputTypes fileType, int width, int height)
        throws PersistenceException {
    info = new ChartRenderingInfo(new StandardEntityCollection());
    if (outputStream == null) {
        outputStream = new ByteArrayOutputStream();
    }/*from  w  ww .  ja v a 2 s .  c  o m*/

    try {
        outputStream.flush();
    } catch (IOException e1) {
        throw new PersistenceException(e1);
    }
    if (fileType == IOutput.OutputTypes.FILE_TYPE_JPEG) {
        try {
            ChartUtilities.writeChartAsJPEG(outputStream, chart, width, height, info);
        } catch (IOException e) {
            throw new PersistenceException(e);
        }
    } else if ((fileType == IOutput.OutputTypes.FILE_TYPE_PNG) || (fileType == null)) {
        try {
            ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, info);
        } catch (IOException e) {
            throw new PersistenceException(e);
        }
    }
    return outputStream;
}

From source file:org.n52.server.io.EESGenerator.java

@Override
public RepresentationResponse producePresentation(DesignOptions options) throws GeneratorException {
    ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
    String chartUrl = createChart(options, renderingInfo);

    Rectangle2D plotArea = renderingInfo.getPlotInfo().getDataArea();
    for (Axis axis : renderer.getAxisMapping().values()) {
        axis.setMaxY(plotArea.getMaxY());
        axis.setMinY(plotArea.getMinY());
    }//from  w ww.  ja  v a  2  s  . c o  m

    ImageEntity[] entities = {};
    if (!this.isOverview) {
        LOGGER.debug("Produced EES diagram " + chartUrl);
        entities = createImageEntities(renderingInfo.getEntityCollection());
    } else {
        LOGGER.debug("Produced EES Overview diagram " + chartUrl);
    }

    Bounds chartArea = new Bounds(plotArea.getMinX(), plotArea.getMaxX(), plotArea.getMinY(),
            plotArea.getMaxY());
    return new EESDataResponse(chartUrl, options, chartArea, entities, renderer.getAxisMapping());
}

From source file:gov.nih.nci.cma.web.graphing.PCAPlot.java

public String generatePCAPlotChart(String components, HttpServletRequest request, PrintWriter pw) {
    String finalURLpath = null; //imageHandler.getFinalURLPath();
    try {//  w w w.j  av  a 2  s . com
        //check the components to see which graph to get
        CMAPrincipalComponentAnalysisPlot plot = null;
        if (components.equalsIgnoreCase("PC1vsPC2")) {
            plot = new CMAPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC2, PCAcomponent.PC1,
                    sampleGroupNames);
        }
        if (components.equalsIgnoreCase("PC1vsPC3")) {
            plot = new CMAPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC1,
                    sampleGroupNames);
        }
        if (components.equalsIgnoreCase("PC2vsPC3")) {
            plot = new CMAPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC2,
                    sampleGroupNames);
        }
        chart = plot.getChart();

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        // BW
        if (chart != null) {
            //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue();
            finalURLpath = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, request.getSession());
            CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
            ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer
            //ChartUtilities.writeImageMap(pw, finalURLpath, info,
            //      ttip,
            //      new StandardURLTagFragmentGenerator());
            //ChartUtilities.writeImageMap(pw, finalURLpath, info, true);
            pw.write(ImageMapUtil.getBoundingRectImageMapTag(finalURLpath, false, info));
            info.clear(); // lose the first one
            info = new ChartRenderingInfo(new StandardEntityCollection());
        }

        pw.flush();
    } catch (IOException e) {
        logger.error(e);
    } catch (Exception e) {
        logger.error(e);
    } catch (Throwable t) {
        logger.error(t);
    }
    return finalURLpath;
}

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

private void performChartRendering(DesignOptions options, OutputStream outputStream) {
    try {//  w  ww  .  j a  va2s  . c om
        EESGenerator chartGenerator = new EESGenerator();
        ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
        chartGenerator.createChartToOutputStream(options, renderingInfo, outputStream);
    } catch (Exception e) {
        LOGGER.error("Could not render timeseries chart.", e);
        throw new InternalServiceException();
    }
}

From source file:nl.wur.plantbreeding.www.marker2seq.GoDistribution.java

/**
 * Generate the Pie chart for a set of given Go terms.
 * @param gotermlist of String (here GO names)
 * @param title the title of the GO graph
 * @param url the url used for the tooltips
 * @param session the HttpSession used to save the file
 * @param legend Print the legend or not
 * @param tooltips Add tooltip or not//from   www  .  ja v  a  2  s.  c  o  m
 * @param urls Add urls or not (link in the graph)
 * @param max Maximum number of item to display
 * @return a list containing the filename and the map for the figure
 * @throws IOException when something happens while writting the image
 */
public static String[] generateDistribution(final List<String> gotermlist, final String title, final String url,
        final HttpSession session, final boolean legend, final boolean tooltips, final boolean urls,
        final int max) throws IOException {
    final PieChart piec = new PieChart();
    final PieDataset dataset = piec.createDataset(gotermlist);
    final JFreeChart chart = piec.createChart(dataset, title, legend, tooltips, urls);
    final PiePlot plot = (PiePlot) chart.getPlot();
    if (gotermlist.size() >= max) {
        plot.setLabelGenerator(null);
    }
    plot.setURLGenerator(new StandardPieURLGenerator(url, "section"));

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

    final String filename = ServletUtilities.saveChartAsPNG(chart, 500, 400, info, session);

    final String map = ChartUtilities.getImageMap(filename, info);

    final String[] output = { filename, map };
    return output;

}

From source file:org.gaixie.micrite.action.GenericAction.java

public void putChartResultList(JFreeChart chart) {
    StandardEntityCollection entityCollection = new StandardEntityCollection();
    ChartRenderingInfo info = new ChartRenderingInfo(entityCollection);
    String filename = "";
    try {/*  ww w  .  ja  v a  2s.co  m*/
        filename = ServletUtilities.saveChartAsPNG(chart, getChartWidth(), getChartHeight(), info, null);
        String mapName = "map" + new Date();
        String mapInfo = ChartUtilities.getImageMap(mapName, info);
        resultMap.put("success", true);
        resultMap.put("filename", filename);
        resultMap.put("map", mapInfo);
        resultMap.put("mapName", mapName);
    } catch (IOException e) {
        resultMap.put("success", false);
    }
}

From source file:org.jfree.chart.demo.ImageMapDemo6.java

/**
 * Saves the chart image and HTML.//  w ww  .j  ava2  s.co  m
 */
public void saveImageAndHTML() {

    final CategoryDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("multipiechart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("multipiechart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"multipiechart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
}

From source file:playground.anhorni.crossborder.verification.Verification.java

private void writeTGZMGraph() {

    int width = 800;
    int height = 600;

    for (int i = 0; i < 4; i++) {
        TGZMCompare tgzm = new TGZMCompare(this.xTripsPerHour[i], this.aggregatedVolumePerHourTGZM[i]);

        JFreeChart chart = tgzm.createChart(this.getActTypeString(i));
        String fileName = "TGZMCompare" + this.getActTypeString(i);

        try {/*from  w ww  .  j a va 2  s.  co m*/
            ChartRenderingInfo info = null;
            info = new ChartRenderingInfo(new StandardEntityCollection());
            File file1 = new File("output/" + fileName + ".png");
            ChartUtilities.saveChartAsPNG(file1, chart, width, height, info);
        } catch (IOException e) {
            System.out.println(e.toString());
        } //catch   
    }

    int[] sumTripsPerHour = new int[24];
    double[] sumAggregatedVolumePerHour = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

    for (int i = 0; i < 24; i++) {
        for (int j = 0; j < 4; j++) {
            sumTripsPerHour[i] += this.xTripsPerHour[j][i];
            sumAggregatedVolumePerHour[i] += this.aggregatedVolumePerHourTGZM[j][i];
        }
    }

    TGZMCompare tgzm = new TGZMCompare(sumTripsPerHour, sumAggregatedVolumePerHour);
    JFreeChart chart = tgzm.createChart("All");
    String fileName = "TGZMCompare All";

    try {
        ChartRenderingInfo info = null;
        info = new ChartRenderingInfo(new StandardEntityCollection());
        File file1 = new File("output/" + fileName + ".png");
        ChartUtilities.saveChartAsPNG(file1, chart, width, height, info);
    } catch (IOException e) {
        System.out.println(e.toString());
    } //catch
}

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

private void performChartRendering(DesignOptions options, OutputStream outputStream) {
    try {/*ww  w .jav  a 2 s  . c o  m*/
        EESGenerator chartGenerator = new EESGenerator();
        ChartRenderingInfo renderingInfo = new ChartRenderingInfo(new StandardEntityCollection());
        chartGenerator.createChartToOutputStream(options, renderingInfo, outputStream);
    } catch (Exception e) {
        LOGGER.error("Could not render timeseries chart.", e);
        throw new InternalServerException("internal error!", e);
    }
}

From source file:org.jfree.chart.demo.ImageMapDemo5.java

/**
 * Saves the chart image and HTML.//  w w  w . j  a  va2  s  .  c  om
 */
public void saveImageAndHTML() {

    // create a dataset
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    final JFreeChart chart = createChart(dataset);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("areachart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("areachart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"areachart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
}