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:gov.nih.nci.ispy.web.taglib.CorrScatterPlotTag.java

public int doStartTag() {
    chart = null;//from  ww w  . jav  a 2 s  .co m
    plotPoints.clear();

    ServletRequest request = pageContext.getRequest();
    HttpSession session = pageContext.getSession();
    Object o = request.getAttribute(beanName);
    JspWriter out = pageContext.getOut();
    ServletResponse response = pageContext.getResponse();

    try {
        //retrieve the Finding from cache and build the list of PCAData points
        ISPYCorrelationFinding corrFinding = (ISPYCorrelationFinding) businessTierCache
                .getSessionFinding(session.getId(), taskId);

        Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>();
        List<String> sampleIds = new ArrayList<String>();

        List<DataPoint> points = corrFinding.getDataPoints();

        ClinicalDataService cqs = ClinicalDataServiceFactory.getInstance();
        IdMapperFileBasedService idMapper = IdMapperFileBasedService.getInstance();

        List<ISPYPlotPoint> plotPoints = new ArrayList<ISPYPlotPoint>();
        ISPYPlotPoint pp;
        SampleInfo si;
        ISPYclinicalDataQueryDTO dto;
        Set<String> sampleHolder = new HashSet<String>(); //set just holds one entry need this for the dto
        Set<PatientData> dataHolder = new HashSet<PatientData>();
        PatientData pd = null;
        for (DataPoint p : points) {
            pp = new ISPYPlotPoint(p.getId());
            pp.setX(p.getX());
            pp.setY(p.getY());
            pp.setZ(p.getZ());

            String patientId = null;

            if (corrFinding.isSampleBased()) {
                si = idMapper.getSampleInfoForLabtrackId(p.getId());
                if (si != null) {
                    pp.setSampleInfo(si);
                    patientId = si.getISPYId();
                } else {
                    logger.warn("Could not get sample info for DataPoint=" + p.getId());
                }
            } else if (corrFinding.isPatientBased()) {
                patientId = p.getId();
            }

            if (patientId != null) {
                dto = new ISPYclinicalDataQueryDTO();
                sampleHolder.clear();
                sampleHolder.add(patientId);
                dto.setRestrainingSamples(sampleHolder);
                dataHolder.clear();
                dataHolder = cqs.getClinicalData(dto);

                if (dataHolder.size() == 1) {
                    Iterator i = dataHolder.iterator();
                    pd = (PatientData) i.next();
                    pp.setPatientData(pd);
                } else {
                    logger.error("Internal Error. Did not get back correct patient data for  patientId="
                            + patientId);
                }
            }

            plotPoints.add(pp);
        }

        ISPYCorrelationScatterPlot plot = new ISPYCorrelationScatterPlot(plotPoints,
                corrFinding.getGroup1Name(), corrFinding.getGroup2Name(), corrFinding.getContinuousType1(),
                corrFinding.getContinuousType2(), corrFinding.getCorrelationValue(),
                ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase()));
        chart = plot.getChart();
        ISPYImageFileHandler imageHandler = new ISPYImageFileHandler(session.getId(), "png", 650, 600);
        //The final complete path to be used by the webapplication
        String finalPath = imageHandler.getSessionTempFolder();
        String finalURLpath = imageHandler.getFinalURLPath();
        /*
         * Create the actual charts, writing it to the session temp folder
        */
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        String mapName = imageHandler.createUniqueMapName();
        //PrintWriter writer = new PrintWriter(new FileWriter(mapName));
        ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info);
        //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true);
        //writer.close();

        /*   This is here to put the thread into a loop while it waits for the
         *   image to be available.  It has an unsophisticated timer but at 
         *   least it is something to avoid an endless loop.
         **/
        boolean imageReady = false;
        int timeout = 1000;
        FileInputStream inputStream = null;
        while (!imageReady) {
            timeout--;
            try {
                inputStream = new FileInputStream(finalPath);
                inputStream.available();
                imageReady = true;
                inputStream.close();
            } catch (IOException ioe) {
                imageReady = false;
                if (inputStream != null) {
                    inputStream.close();
                }
            }
            if (timeout <= 1) {

                break;
            }
        }

        out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, true, info));
        finalURLpath = finalURLpath.replace("\\", "/");
        long randomness = System.currentTimeMillis(); //prevent image caching
        out.print("<img id=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness
                + "\" usemap=\"#" + mapName + "\" border=\"0\" />");

        //(imageHandler.getImageTag(mapFileName));

    } catch (IOException e) {
        logger.error(e);
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        logger.error(sw.toString());
    } catch (Throwable t) {
        logger.error(t);
    }

    return EVAL_BODY_INCLUDE;
}

From source file:chart.statistic.HistogramChart.java

public void store(JFreeChart cp, File folder, String filename) {
    if (doStoreChart) {

        //            File folder = LogFile.folderFile;
        //            String fn = folder.getAbsolutePath() + File.separator + "images/Distribution_";
        //            File file = null;
        //            fn = fn + GeneralResultRecorder.currentSimulationLabel;

        String fn = filename;/*from w w  w .  ja v a2s.c o  m*/
        try {

            final File file1 = new File(folder.getAbsolutePath() + File.separator + fn + ".png");
            System.out
                    .println("\n>>> Save as PNG Image - Filename: " + file1.getAbsolutePath() + "; CP: " + cp);
            try {
                final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

                Thread.currentThread().sleep(1000);

                ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

                Thread.currentThread().sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }

            //                File file = new File(folder.getAbsolutePath() + File.separator + fn + ".svg");
            //                System.out.println(">>> Save as SVG Image - Filename: " + file.getAbsolutePath()
            //                        + "; CP: "+ cp);
            //
            //
            //                // Get a DOMImplementation and create an XML document
            //                DOMImplementation domImpl =
            //                        GenericDOMImplementation.getDOMImplementation();
            //                Document document = domImpl.createDocument(null, "svg", null);
            //
            //                // Create an instance of the SVG Generator
            //                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
            //
            //                // draw the chart in the SVG generator
            //                cp.draw(svgGenerator, new Rectangle(800, 600));
            //
            //                // Write svg file
            //                OutputStream outputStream = new FileOutputStream(file);
            //                Writer out = new OutputStreamWriter(outputStream, "UTF-8");
            //                svgGenerator.stream(out, true /* use css */);
            //                outputStream.flush();
            //                outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.efs.openreports.engine.ChartReportEngine.java

private static ChartEngineOutput createChartOutput(ReportChart reportChart, ChartValue[] values) {
    JFreeChart chart = null;//  w w w  . ja v a  2  s.co m

    switch (reportChart.getChartType()) {
    case ReportChart.BAR_CHART:
        chart = createBarChart(reportChart, values);
        break;
    case ReportChart.PIE_CHART:
        chart = createPieChart(reportChart, values);
        break;
    case ReportChart.XY_CHART:
        chart = createXYChart(reportChart, values);
        break;
    case ReportChart.TIME_CHART:
        chart = createTimeChart(reportChart, values);
        break;
    case ReportChart.RING_CHART:
        chart = createRingChart(reportChart, values);
        break;
    }

    if (chart == null)
        return null;

    chart.setBackgroundPaint(Color.WHITE);

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

    BufferedImage bufferedImage = chart.createBufferedImage(reportChart.getWidth(), reportChart.getHeight(),
            info);
    byte[] image = null;

    try {
        image = EncoderUtil.encode(bufferedImage, ImageFormat.JPEG);
    } catch (IOException ioe) {
        log.warn(ioe);
    }

    ChartEngineOutput chartOutput = new ChartEngineOutput();
    chartOutput.setContent(image);
    chartOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_JPEG);
    chartOutput.setChartRenderingInfo(info);
    chartOutput.setChartValues(values);

    return chartOutput;
}

From source file:org.squale.squaleweb.applicationlayer.action.results.project.TopAction.java

/**
 * Redirige vers une jsp affichant le scatterplott
 * //from   www  .j av  a 2 s  .  c om
 * @param pMapping le mapping.
 * @param pForm le formulaire  lire.
 * @param pRequest la requte HTTP.
 * @param pResponse la rponse de la servlet.
 * @return l'action  raliser.
 */
public ActionForward displayBubble(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest,
        HttpServletResponse pResponse) {
    ActionForward forward = null;
    ActionErrors errors = new ActionErrors();
    try {
        JFreeChart chartBubble = getBubbleChart(pRequest);
        ChartRenderingInfo infoBubble = new ChartRenderingInfo(new StandardEntityCollection());
        // Sauvegarde de l'image du BubbleChart au format png dans le form
        String fileNameBubble = ServletUtilities.saveChartAsPNG(chartBubble, BubbleMaker.DEFAULT_WIDTH,
                BubbleMaker.DEFAULT_HEIGHT, infoBubble, pRequest.getSession());
        GraphMaker projectBubbleGraphMaker = new GraphMaker(pRequest, fileNameBubble, infoBubble);
        pRequest.setAttribute(SqualeWebConstants.BUBBLE_GRAPH_MAKER, projectBubbleGraphMaker);
    } catch (Exception e) {
        handleException(e, errors, pRequest);
    }
    if (!errors.isEmpty()) {
        saveMessages(pRequest, errors);
        forward = pMapping.findForward("total_failure");
    } else {
        forward = pMapping.findForward("displayBubble");
    }
    return forward;
}

From source file:org.pentaho.platform.uifoundation.chart.XYSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();

    setXslProperty("baseUrl", contextPath + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);/*from   ww  w . ja v  a 2 s. c  om*/
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    XYSeriesCollection chartDataDefinition = (XYSeriesCollection) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                Number columnKey = chartDataDefinition.getX(row, column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.XYZSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//from  ww  w  . ja  va2 s .  c om
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    XYZSeriesCollectionChartDefinition chartDataDefinition = (XYZSeriesCollectionChartDefinition) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                Number columnKey = chartDataDefinition.getX(row, column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.PieDatasetChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();

    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);/*from  w w w .  j av  a 2  s  .  c  o m*/
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);
    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/urlTemplate") != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/urlTemplate").getText(); //$NON-NLS-1$
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    DefaultPieDataset chartDataDefinition = (DefaultPieDataset) dataDefinition;
    // if (chartDataDefinition.getRowCount() > 0) {
    // create temporary file names
    String[] tempFileInfo = createTempFile();
    String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
    String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
            JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
    applyOuterURLTemplateParam();
    populateInfo(info);
    Element chartElement = root.addElement("chart"); //$NON-NLS-1$
    chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
    chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
    chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
    // for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
    // for (int column = 0; column < chartDataDefinition.getColumnCount();
    // column++) {
    // Number value = chartDataDefinition.getValue(row, column);
    // Comparable rowKey = chartDataDefinition.getRowKey(row);
    // Comparable columnKey = chartDataDefinition.getColumnKey(column);
    // Element valueElement = chartElement.addElement("value2D");
    // //$NON-NLS-1$
    // valueElement.addElement("value").setText(value.toString());
    // //$NON-NLS-1$
    // valueElement.addElement("row-key").setText(rowKey.toString());
    // //$NON-NLS-1$
    // valueElement.addElement("column-key").setText(columnKey.toString());
    // //$NON-NLS-1$
    // }
    // }
    String mapString = ImageMapUtilities.getImageMap(mapName, info);
    chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
    chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    // }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//w w  w .  ja v a  2  s .co m
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    TimeSeriesCollection chartDataDefinition = (TimeSeriesCollection) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                RegularTimePeriod columnKey = chartDataDefinition.getSeries(row).getTimePeriod(column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

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

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

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

/**
 * Renders a legend//from  w w  w .ja  va  2s. c o  m
 * @param cd the chart iamge to be rendred
 * @return the rendered image
 * @throws CewolfException
 */
private static RenderedImage renderLegend(ChartImage cd, Object c) throws CewolfException {
    try {
        JFreeChart chart = (JFreeChart) c;
        final int width = cd.getWidth();
        final int height = cd.getHeight();
        LegendTitle legend = getLegend(chart);
        boolean haslegend = true;

        // with JFreeChart v0.9.20, the only way to get a valid legend,
        // is either to retrieve it from the chart or to assign a new
        // one to the chart. In the case where the chart has no legend,
        // a new one must be assigned, but just for rendering. After, we
        // have to reset the legend to null in the chart.
        if (null == legend) {
            haslegend = false;
            legend = new LegendTitle(chart.getPlot());
        }
        legend.setPosition(RectangleEdge.BOTTOM);
        BufferedImage bimage = ImageHelper.createImage(width, height);
        Graphics2D g = bimage.createGraphics();
        g.setColor(Color.white);
        g.fillRect(0, 0, width, height);
        legend.arrange(g, new RectangleConstraint(width, height));
        legend.draw(g, new Rectangle(width, height));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
        param.setQuality(1.0f, true);
        encoder.encode(bimage, param);
        out.close();

        // if the chart had no legend, reset it to null in order to give back the
        // chart in the state we received it.
        if (!haslegend) {
            removeLegend(chart);
        }

        return new RenderedImage(out.toByteArray(), "image/jpeg",
                new ChartRenderingInfo(new StandardEntityCollection()));
    } catch (IOException ioex) {
        log.error(ioex);
        throw new ChartRenderingException(ioex.getMessage(), ioex);
    }
}