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.efs.openreports.engine.ChartReportEngine.java

private static ChartEngineOutput createChartOutput(ReportChart reportChart, ChartValue[] values) {
    JFreeChart chart = null;//  www. j a  v  a  2s. 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 ww  w  . j av a  2 s.co  m*/
 * @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.j a  v a2s .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 (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   w w  w .j  a 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$
    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  .java  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 (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);/*from   w w w .  jav 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 (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.
 *//*from  w  w w  .ja  v a2  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  ww  .j  a  v a  2s.c  om*/
 * @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);
    }
}

From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent.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 . 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$
        }
    } catch (NumberFormatException ignored) {
        // go with the default
    }
    try {
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (NumberFormatException ignored) {
        // 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$
    DefaultCategoryDataset chartDataDefinition = (DefaultCategoryDataset) 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.squale.squaleweb.applicationlayer.action.results.application.ApplicationResultsAction.java

/**
 * Synthse d'une application Si l'application comporte un seul projet, la synthse du projet est alors affiche.
 * Dans le cas contraire, trois onglets sont prsents : un qui donne la rpartition, l'autre donnant les facteurs
 * par projet et le dernier donnant le kiviat.
 * /*from  w  w  w.j a  va 2s  . c o  m*/
 * @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 summary(ActionMapping pMapping, ActionForm pForm, HttpServletRequest pRequest,
        HttpServletResponse pResponse) {

    // Cette action est appele dans plusieurs contextes possibles
    // Depuis une action struts avec l'id de l'application ou depuis
    // une page de l'application sans id de l'application (on a alors affaire  l'application courante)
    ActionForward forward;
    try {
        // Add an user access for this application
        addUserAccess(pRequest, ActionUtils.getCurrentApplication(pRequest).getId());
        forward = checkApplication(pMapping, pRequest);
        // Si forward est renseign, l'application contient un seul projet
        // On redirige donc vers le projet adquat
        if (null == forward) {
            // Rcupration des informations concernant les facteurs
            // Rcupration du paramtre : tous les facteurs ou seuls les facteurs ayant une note ?
            ResultListForm resultListForm = (ResultListForm) pForm;
            boolean pAllFactors = resultListForm.isAllFactors();
            // On met cette valeur en session
            pRequest.getSession().setAttribute(ALL_FACTORS, new Boolean(pAllFactors));

            ApplicationForm application = ActionUtils.getCurrentApplication(pRequest);
            // On remet  jour les form en session permettant d'accder aux diffrents types d'audits
            SplitAuditsListForm auditsForm = (SplitAuditsListForm) pRequest.getSession()
                    .getAttribute("splitAuditsListForm");
            if (auditsForm != null) {
                auditsForm.copyValues(application);
                auditsForm.resetAudits(ActionUtils.getCurrentAuditsAsDTO(pRequest));
                pRequest.getSession().setAttribute("splitAuditsListForm", auditsForm);
            }
            List auditsDTO = ActionUtils.getCurrentAuditsAsDTO(pRequest);
            if (auditsDTO != null) {
                ((ResultListForm) pForm).resetAudits(auditsDTO);
            }
            // On efface ce form contenant les erreurs de l'application, car si on passe par ici
            // Ce form ne peut que contenir les informations pour une autre application
            pRequest.getSession().removeAttribute("applicationErrorForm");

            // Prparation de l'appel  la couche mtier
            IApplicationComponent ac = AccessDelegateHelper.getInstance("Results");
            List applications = Arrays
                    .asList(WTransformerFactory.formToObj(ApplicationTransformer.class, application));
            Object[] paramIn = { applications, auditsDTO };
            // Les rsultats sont retourns dans l'ordre impos par la grille
            // on maintient cet ordre pour l'affichage
            List results = (List) ac.execute("getApplicationResults", paramIn);
            pRequest.getSession().removeAttribute(SqualeWebConstants.RESULTS_KEY);
            if (null != results && results.size() > 0) {
                // Transformation des rsultats avant leur affichage par la couche
                // welcom
                WTransformerFactory.objToForm(FactorsResultListTransformer.class, (ResultListForm) pForm,
                        new Object[] { applications, results });
            } else {
                // si aucun resultat => liste vide
                WTransformerFactory.objToForm(FactorsResultListTransformer.class, (ResultListForm) pForm,
                        new Object[] { applications, new ArrayList() });
            }
            // Rcupration des donnes permettant la gnration du Kiviat et du PieChart de l'application
            if (null != auditsDTO && null != auditsDTO.get(0)) {
                // Prparation de l'appel  la couche mtier
                ac = AccessDelegateHelper.getInstance("Graph");
                Long pCurrentAuditId = new Long(((AuditDTO) auditsDTO.get(0)).getID());
                Object[] paramAuditIdKiviat = { pCurrentAuditId, String.valueOf(pAllFactors) };

                // Recherche des donnes Kiviat
                KiviatMaker maker = new KiviatMaker();
                Map projectsValues = (Map) ac.execute("getApplicationKiviatGraph", paramAuditIdKiviat);
                Set keysSet = projectsValues.keySet();
                Iterator it = keysSet.iterator();
                while (it.hasNext()) {
                    String key = (String) it.next();
                    maker.addValues(key, (SortedMap) projectsValues.get(key), pRequest);
                }
                JFreeChart chartKiviat = maker.getChart();
                ChartRenderingInfo infoKiviat = new ChartRenderingInfo(new StandardEntityCollection());
                // Initialisation du kiviat
                String fileNameKiviat = ServletUtilities.saveChartAsPNG(chartKiviat, KiviatMaker.DEFAULT_WIDTH,
                        KiviatMaker.DEFAULT_HEIGHT, infoKiviat, pRequest.getSession());
                GraphMaker applicationKiviatChart = new GraphMaker(pRequest, fileNameKiviat, infoKiviat);

                // Pour l'export en PDF
                pRequest.getSession().removeAttribute("kiviatChart");
                pRequest.getSession().setAttribute("kiviatChart",
                        chartKiviat.createBufferedImage(KiviatMaker.DEFAULT_WIDTH, KiviatMaker.DEFAULT_HEIGHT));

                // Recherche des donnes PieChart
                Object[] paramAuditIdPieChart = { pCurrentAuditId };
                JFreeChart pieChart;
                Object[] maps = (Object[]) ac.execute("getApplicationPieChartGraph", paramAuditIdPieChart);
                String pPreviousAuditId = null;
                // on peut ne pas avoir d'audit prcdent
                if (auditsDTO.size() > 1) {
                    pPreviousAuditId = "" + ((AuditDTO) auditsDTO.get(1)).getID();
                }
                PieChartMaker pieMaker = new PieChartMaker(null, pCurrentAuditId.toString(), pPreviousAuditId);
                pieMaker.setValues((Map) maps[0]);
                pieChart = pieMaker.getChart((Map) maps[1], pRequest);

                ChartRenderingInfo infoPieChart = new ChartRenderingInfo(new StandardEntityCollection());
                // Initialisation du pieChart
                String fileName = ServletUtilities.saveChartAsPNG(pieChart, PieChartMaker.DEFAULT_WIDTH,
                        PieChartMaker.DEFAULT_HEIGHT, infoPieChart, pRequest.getSession());
                GraphMaker applicationPieChart = new GraphMaker(pRequest, fileName, infoPieChart);

                // Met  jour les 2 champs du form avec les 2 graphs calculs
                ((ResultListForm) pForm).setKiviat(applicationKiviatChart);
                ((ResultListForm) pForm).setPieChart(applicationPieChart);

                // Met  jour le form en session
                pRequest.getSession().setAttribute("resultListForm", pForm);

                // Pour l'export en PDF
                pRequest.getSession().removeAttribute("pieChart");
                pRequest.getSession().setAttribute("pieChart", pieChart
                        .createBufferedImage(PieChartMaker.DEFAULT_WIDTH, PieChartMaker.DEFAULT_HEIGHT));
            }
            // Affichage des informations sur la page jsp
            forward = pMapping.findForward("summary");
        }
    } catch (Exception e) {
        ActionErrors errors = new ActionErrors();
        // Traitement factoris des erreurs
        handleException(e, errors, pRequest);
        // Sauvegarde des erreurs
        saveMessages(pRequest, errors);
        // Routage vers la page d'erreur
        forward = pMapping.findForward("total_failure");
    }
    // On est pass par un menu donc on rinitialise le traceur
    resetTracker(pRequest);
    // Indique que l'on vient d'une vue synthse et pas d'une vue composant
    changeWay(pRequest, "false");
    return forward;
}