Example usage for org.jfree.chart JFreeChart getTitle

List of usage examples for org.jfree.chart JFreeChart getTitle

Introduction

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

Prototype

public TextTitle getTitle() 

Source Link

Document

Returns the main chart title.

Usage

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();//from ww w  .  j  a v a2  s. c  o m

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

From source file:bestdeal.gui.Statistique.java

/**
 * Creates new form Statistique//from  w  w  w  . j a  v a 2s  .  c o  m
 */
@SuppressWarnings("empty-statement")
public Statistique() {
    initComponents();

    btn_retour.setIcon((Icon) new ImageIcon("C:\\Users\\Jedidi\\Desktop\\icone\\retour.png"));
    panel = new ImagePanel(new ImageIcon("C:\\Users\\Jedidi\\Desktop\\111.jpg").getImage());
    Panel.add(panel);
    lbl_log.setIcon((Icon) new ImageIcon("C:\\Users\\Jedidi\\Desktop\\Logo_.png"));

    SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy");
    lbl_date1.setText(sdf1.format(new java.util.Date()));
    SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
    lbl_heure.setText(sdf2.format(new java.util.Date()));

    final DefaultPieDataset objDataset = new DefaultPieDataset();
    VoucherDAO v2 = new VoucherDAO();
    String[][] stat = v2.StatDeal();

    objDataset.setValue(stat[0][0], Integer.parseInt(stat[9][0]));
    objDataset.setValue(stat[0][1], Integer.parseInt(stat[9][1]));
    objDataset.setValue(stat[0][2], Integer.parseInt(stat[9][2]));
    objDataset.setValue(stat[0][3], Integer.parseInt(stat[9][3]));
    objDataset.setValue(stat[0][4], Integer.parseInt(stat[9][4]));

    JFreeChart objChart = ChartFactory.createPieChart3D("Best 5 deals", objDataset, true, true, true);
    //String textTitle = "Best 5 deals";
    TextTitle textTitle = objChart.getTitle();
    textTitle.setFont(new Font("Arial", Font.BOLD, 15));

    panel_deals.setLayout(new java.awt.BorderLayout());
    panel_clients.setLayout(new java.awt.BorderLayout());
    panel_vendeurs.setLayout(new java.awt.BorderLayout());
    final ChartPanel CP = new ChartPanel(objChart);
    CP.setPreferredSize(new java.awt.Dimension(600, 500));
    panel_deals.add(CP, BorderLayout.WEST);
    panel_deals.validate();

    TabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (TabbedPane.getSelectedIndex() == 0) {

                objDataset.clear();
                VoucherDAO v2 = new VoucherDAO();
                String[][] stat = v2.StatDeal();

                objDataset.setValue(stat[0][0], Integer.parseInt(stat[9][0]));
                objDataset.setValue(stat[0][1], Integer.parseInt(stat[9][1]));
                objDataset.setValue(stat[0][2], Integer.parseInt(stat[9][2]));
                objDataset.setValue(stat[0][3], Integer.parseInt(stat[9][3]));
                objDataset.setValue(stat[0][4], Integer.parseInt(stat[9][4]));

                panel_deals.add(CP, BorderLayout.WEST);
                panel_deals.validate();

            } else if (TabbedPane.getSelectedIndex() == 1) {

                objDataset.clear();
                VoucherDAO v2 = new VoucherDAO();
                String[][] stat = v2.StatVendeur();

                objDataset.setValue(stat[1][0], Integer.parseInt(stat[7][0]));
                objDataset.setValue(stat[1][1], Integer.parseInt(stat[7][1]));
                objDataset.setValue(stat[1][2], Integer.parseInt(stat[7][2]));
                objDataset.setValue(stat[1][3], Integer.parseInt(stat[7][3]));
                objDataset.setValue(stat[1][4], Integer.parseInt(stat[7][4]));

                panel_vendeurs.add(CP, BorderLayout.WEST);
                panel_vendeurs.validate();

            } else if (TabbedPane.getSelectedIndex() == 2) {

                objDataset.clear();
                VoucherDAO v2 = new VoucherDAO();
                String[][] stat = v2.StatClient();

                objDataset.setValue(stat[1][0], Integer.parseInt(stat[4][0]));
                objDataset.setValue(stat[1][1], Integer.parseInt(stat[4][1]));
                objDataset.setValue(stat[1][2], Integer.parseInt(stat[4][2]));
                objDataset.setValue(stat[1][3], Integer.parseInt(stat[4][3]));
                objDataset.setValue(stat[1][4], Integer.parseInt(stat[4][4]));

                panel_clients.add(CP, BorderLayout.WEST);
                panel_clients.validate();
            } else if (TabbedPane.getSelectedIndex() == 3) {

            }

        }
    });

}

From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java

protected JFreeChart getPredictedTargetsChart(TSForecaster forecaster, ErrorModule preds,
        List<String> targetNames, int stepNumber, int instanceNumOffset, Instances data) {

    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) {

            // fill in any missing time stamps only
            data = new Instances(data);
            data = weka.classifiers.timeseries.core.Utils.replaceMissing(data, null,
                    lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries());
        }/*w w  w . j  a  v a  2 s .  co  m*/
    }

    // set up a collection of predicted and actual series
    XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection();
    for (String target : targetNames) {
        XYIntervalSeries targetSeries = new XYIntervalSeries(target + "-actual", false, false);
        xyDataset.addSeries(targetSeries);
        targetSeries = new XYIntervalSeries(target + "-predicted", false, false);
        xyDataset.addSeries(targetSeries);

    }

    ValueAxis timeAxis = null;
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false);
    int timeIndex = -1;
    boolean timeAxisIsDate = false;
    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) {
            String timeName = lagMaker.getTimeStampField();
            if (data.attribute(timeName).isDate()) {
                timeAxis = new DateAxis("");
                timeAxisIsDate = true;
                timeIndex = data.attribute(timeName).index();
            }
        }
    }

    if (timeAxis == null) {
        timeAxis = new NumberAxis("");
        ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false);
    }

    // now populate the series
    boolean hasConfidenceIntervals = false;
    for (int i = 0; i < targetNames.size(); i++) {
        String targetName = targetNames.get(i);
        List<NumericPrediction> predsForI = preds.getPredictionsForTarget(targetName);
        int predIndex = xyDataset.indexOf(targetName + "-predicted");
        int actualIndex = xyDataset.indexOf(targetName + "-actual");
        XYIntervalSeries predSeries = xyDataset.getSeries(predIndex);
        XYIntervalSeries actualSeries = xyDataset.getSeries(actualIndex);

        for (int j = 0; j < predsForI.size(); j++) {
            double x = Utils.missingValue();
            if (timeAxisIsDate) {
                if (instanceNumOffset + j + stepNumber - 1 < data.numInstances()) {
                    x = data.instance(instanceNumOffset + j + stepNumber - 1).value(timeIndex);
                }
            } else {
                x = instanceNumOffset + j + stepNumber;
            }

            double yPredicted = predsForI.get(j).predicted();
            double yHigh = yPredicted;
            double yLow = yPredicted;
            double[][] conf = predsForI.get(j).predictionIntervals();
            if (conf.length > 0) {
                yLow = conf[0][0];
                yHigh = conf[0][1];
                hasConfidenceIntervals = true;
            }
            if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yPredicted)) {
                if (predSeries != null) {
                    predSeries.add(x, x, x, yPredicted, yLow, yHigh);
                }
                // System.err.println("* " + yPredicted + " " + x);
            }

            double yActual = predsForI.get(j).actual();
            if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) {
                if (actualSeries != null) {
                    actualSeries.add(x, x, x, yActual, yActual, yActual);
                }
            }
        }
    }

    // set up the chart
    String title = "" + stepNumber + " step-ahead predictions for: ";
    for (String s : targetNames) {
        title += s + ",";
    }
    title = title.substring(0, title.lastIndexOf(","));

    /*
     * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec
     * + ")";
     */

    if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) {
        double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0;
        title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]";
    }

    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setBaseLinesVisible(true);
    renderer.setDrawXError(false);
    renderer.setDrawYError(true);
    // renderer.setShapesFilled(true);
    XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(java.awt.Color.white);
    TextTitle chartTitle = chart.getTitle();
    String fontName = chartTitle.getFont().getFontName();
    java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12);
    chartTitle.setFont(newFont);

    return chart;
}

From source file:net.sf.jasperreports.components.spiderchart.FillSpiderChart.java

protected JFreeChart evaluateChart(byte evaluation) throws JRException {
    maxValue = (Double) fillContext.evaluate(getPlot().getMaxValueExpression(), evaluation);
    titleText = (String) fillContext.evaluate(getChartSettings().getTitleExpression(), evaluation);
    subtitleText = (String) fillContext.evaluate(getChartSettings().getSubtitleExpression(), evaluation);
    anchorName = (String) fillContext.evaluate(getChartSettings().getAnchorNameExpression(), evaluation);
    hyperlinkReference = (String) fillContext.evaluate(getChartSettings().getHyperlinkReferenceExpression(),
            evaluation);/*from  w w w .  j  a  v a 2 s  .c o  m*/
    hyperlinkAnchor = (String) fillContext.evaluate(getChartSettings().getHyperlinkAnchorExpression(),
            evaluation);
    hyperlinkPage = (Integer) fillContext.evaluate(getChartSettings().getHyperlinkPageExpression(), evaluation);
    hyperlinkTooltip = (String) fillContext.evaluate(getChartSettings().getHyperlinkTooltipExpression(),
            evaluation);
    hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(getChartSettings(),
            expressionEvaluator, evaluation);

    dataset.evaluateDatasetRun(evaluation);
    dataset.finishDataset();

    chartHyperlinkProvider = new CategoryChartHyperlinkProvider(dataset.getItemHyperlinks());

    bookmarkLevel = getChartSettings().getBookmarkLevel();

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot((DefaultCategoryDataset) dataset.getCustomDataset());

    if (getPlot().getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(getPlot().getAxisLineColor());
    }
    if (getPlot().getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(getPlot().getAxisLineWidth()));
    }
    if (getPlot().getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(getPlot().getBackcolor());
    }
    if (getPlot().getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(getPlot().getBackgroundAlpha());
    }
    if (getPlot().getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(getPlot().getForegroundAlpha());
    }
    if (getPlot().getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(getPlot().getHeadPercent());
    }
    if (getPlot().getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(getPlot().getInteriorGap());
    }
    if (getPlot().getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(getPlot().getLabelColor());
    }
    if (getPlot().getLabelFont() != null) {
        spiderWebPlot.setLabelFont(JRFontUtil.getAwtFont(getPlot().getLabelFont(), Locale.getDefault()));
    }
    if (getPlot().getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(getPlot().getLabelGap());
    }
    if (maxValue != null) {
        spiderWebPlot.setMaxValue(maxValue);
    }
    if (getPlot().getRotation() != null) {
        spiderWebPlot.setDirection(getPlot().getRotation().getRotation());
    }
    if (getPlot().getStartAngle() != null) {
        spiderWebPlot.setStartAngle(getPlot().getStartAngle());
    }
    if (getPlot().getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(getPlot().getTableOrder().getOrder());
    }
    if (getPlot().getWebFilled() != null) {
        spiderWebPlot.setWebFilled(getPlot().getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(new StandardCategoryItemLabelGenerator());

    Font titleFont = getChartSettings().getTitleFont() != null
            ? JRFontUtil.getAwtFont(getChartSettings().getTitleFont(), Locale.getDefault())
            : TextTitle.DEFAULT_FONT;

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    if (chartSettings.getBackcolor() != null) {
        jfreechart.setBackgroundPaint(chartSettings.getBackcolor());
    }

    RectangleEdge titleEdge = getEdge(getChartSettings().getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (getChartSettings().getTitleColor() != null) {
            title.setPaint(getChartSettings().getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (getChartSettings().getSubtitleColor() != null) {
            subtitle.setPaint(getChartSettings().getSubtitleColor());
        }

        if (getChartSettings().getSubtitleColor() != null) {
            Font subtitleFont = getChartSettings().getSubtitleFont() != null
                    ? JRFontUtil.getAwtFont(getChartSettings().getSubtitleFont(), Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (getChartSettings().getLegendColor() != null) {
                legend.setItemPaint(getChartSettings().getLegendColor());
            }
            if (getChartSettings().getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(getChartSettings().getLegendBackgroundColor());
            }

            if (getChartSettings().getLegendFont() != null) {
                legend.setItemFont(
                        JRFontUtil.getAwtFont(getChartSettings().getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(getChartSettings().getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }
    return jfreechart;

}

From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time",
            mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);/*from w w w .  java2 s  .  co m*/
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // format the date axis
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm"));
    axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    axis.setVerticalTickLabels(true);
    return chart;
}

From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java

protected JFreeChart getPredictedStepsChart(TSForecaster forecaster, List<ErrorModule> preds, String targetName,
        List<Integer> stepsToPlot, int instanceNumOffset, Instances data) {

    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) {

            // fill in any missing time stamps only
            data = new Instances(data);
            data = weka.classifiers.timeseries.core.Utils.replaceMissing(data, null,
                    lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries());
        }/*from w w  w  .  j a  v a 2 s. co  m*/
    }

    // set up a collection of predicted series
    XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection();

    XYIntervalSeries targetSeries = new XYIntervalSeries(targetName, false, false);
    xyDataset.addSeries(targetSeries);
    // for (int i = 0; i < preds.size(); i++) {
    for (int z = 0; z < stepsToPlot.size(); z++) {
        int i = stepsToPlot.get(z);
        i--;
        // ignore out of range steps
        if (i < 0 || i >= preds.size()) {
            continue;
        }

        String step = "-steps";
        if (i == 0) {
            step = "-step";
        }
        targetSeries = new XYIntervalSeries(targetName + "_" + (i + 1) + step + "-ahead", false, false);
        xyDataset.addSeries(targetSeries);
    }

    ValueAxis timeAxis = null;
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false);
    int timeIndex = -1;
    boolean timeAxisIsDate = false;
    if (forecaster instanceof TSLagUser && data != null) {
        TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker();
        if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) {
            String timeName = lagMaker.getTimeStampField();
            if (data.attribute(timeName).isDate()) {
                timeAxis = new DateAxis("");
                timeAxisIsDate = true;
                timeIndex = data.attribute(timeName).index();
            }
        }
    }

    if (timeAxis == null) {
        timeAxis = new NumberAxis("");
        ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false);
    }

    // now populate the series
    // for (int i = 0; i < preds.size(); i++) {
    boolean doneActual = false;
    boolean hasConfidenceIntervals = false;
    for (int z = 0; z < stepsToPlot.size(); z++) {
        int i = stepsToPlot.get(z);
        i--;

        // ignore out of range steps
        if (i < 0 || i >= preds.size()) {
            continue;
        }
        ErrorModule predsForStepI = preds.get(i);
        List<NumericPrediction> predsForTargetAtI = predsForStepI.getPredictionsForTarget(targetName);

        String step = "-steps";
        if (i == 0) {
            step = "-step";
        }
        int predIndex = xyDataset.indexOf(targetName + "_" + (i + 1) + step + "-ahead");
        XYIntervalSeries predSeries = xyDataset.getSeries(predIndex);
        XYIntervalSeries actualSeries = null;
        if (!doneActual) {
            int actualIndex = xyDataset.indexOf(targetName);
            actualSeries = xyDataset.getSeries(actualIndex);
        }

        for (int j = 0; j < predsForTargetAtI.size(); j++) {
            double x = Utils.missingValue();
            if (timeAxisIsDate) {
                if (instanceNumOffset + j + i < data.numInstances()) {
                    x = data.instance(instanceNumOffset + j + i).value(timeIndex);
                }
            } else {
                x = instanceNumOffset + j + i;
            }

            double yPredicted = predsForTargetAtI.get(j).predicted();
            double yHigh = yPredicted;
            double yLow = yPredicted;
            double[][] conf = predsForTargetAtI.get(j).predictionIntervals();
            if (conf.length > 0) {
                yLow = conf[0][0];
                yHigh = conf[0][1];
                hasConfidenceIntervals = true;
            }
            if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yPredicted)) {
                if (predSeries != null) {
                    predSeries.add(x, x, x, yPredicted, yLow, yHigh);
                }
                // System.err.println("* " + yPredicted + " " + x);
            }

            if (!doneActual && actualSeries != null) {
                double yActual = predsForTargetAtI.get(j).actual();
                if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) {
                    actualSeries.add(x, x, x, yActual, yActual, yActual);
                }
            }
        }

        if (actualSeries != null) {
            doneActual = true;
        }
    }

    // set up the chart
    String title = "";
    for (int i : stepsToPlot) {
        title += i + ",";
    }
    title = title.substring(0, title.lastIndexOf(","));
    title += " step-ahead predictions for " + targetName;

    /*
     * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec
     * + ")";
     */

    if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) {
        double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0;
        title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]";
    }

    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setBaseLinesVisible(true);
    // renderer.setShapesFilled(true);
    XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    chart.setBackgroundPaint(java.awt.Color.white);
    TextTitle chartTitle = chart.getTitle();
    String fontName = chartTitle.getFont().getFontName();
    java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12);
    chartTitle.setFont(newFont);

    return chart;
}

From source file:result.analysis.Chart.java

private void save_jpeg(JFreeChart chart) {
    BufferedImage objBufferedImage = chart.createBufferedImage(1200, 900);
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    try {//from   w ww.  j av a 2 s .  c  om
        ImageIO.write(objBufferedImage, "png", bas);
    } catch (IOException e) {
        e.printStackTrace();
    }

    byte[] byteArray = bas.toByteArray();
    InputStream in = new ByteArrayInputStream(byteArray);
    BufferedImage image = null;
    try {
        image = ImageIO.read(in);
    } catch (IOException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    File outputfile = new File("Analysis files\\" + chart.getTitle().toString() + ".png");
    try {
        ImageIO.write(image, "png", outputfile);
    } catch (IOException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java

private File createImage(ApplicationGroup appgroup) throws IOException {

    Map<String, Double> costs = Maps.newHashMap();
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    Interval interval = new Interval(end.minusWeeks(numWeeks), end);

    for (Product product : products) {
        List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
        if (resourceGroups.size() == 0) {
            continue;
        }//from   w  w  w. j a  v a2s  .  c om
        DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
        if (dataManager == null) {
            continue;
        }
        TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null,
                resourceGroups);
        Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none,
                false);
        for (Tag tag : data.keySet()) {
            for (int week = 0; week < numWeeks; week++) {
                String key = tag + "|" + week;
                if (costs.containsKey(key))
                    costs.put(key, data.get(tag)[week] + costs.get(key));
                else
                    costs.put(key, data.get(tag)[week]);
            }
        }
    }

    boolean hasData = false;
    for (Map.Entry<String, Double> entry : costs.entrySet()) {
        if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
            hasData = true;
            break;
        }
    }
    if (!hasData)
        return null;

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Product product : products) {
        for (int week = 0; week < numWeeks; week++) {
            String weekStr = String.format("%s - %s week",
                    formatter.print(end.minusWeeks(numWeeks - week)).substring(5),
                    formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
            dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "",
            "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
    renderer.setItemLabelAnchorOffset(10.0);
    TextTitle title = chart.getTitle();
    title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {
        public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row,
                int column) {
            return costFormatter.format(dataset.getValue(row, column));
        }
    });
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(costFormatter);

    BufferedImage image = chart.createBufferedImage(1200, 400);
    File outputfile = File.createTempFile("awscost", "png");
    ImageIO.write(image, "png", outputfile);

    return outputfile;
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC bZhou Comment method "decorateCategoryPlot".
 * /*from w ww . j  ava  2s  .  co m*/
 * @param chart
 */
public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) {

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer render = plot.getRenderer();
    CategoryAxis domainAxis = plot.getDomainAxis();
    // ADD msjian TDQ-5111 2012-4-9: set something look it well
    domainAxis.setCategoryMargin(0.1);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);
    domainAxis.setCategoryLabelPositionOffset(10);
    // TDQ-5111~

    ValueAxis valueAxis = plot.getRangeAxis();

    Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$

    render.setBaseItemLabelFont(font);
    // MOD zshen 10998: change the font name 2010-01-16
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    valueAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);

    setLegendFont(chart);

    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }

    font = null;

    if (render instanceof BarRenderer) {
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        if (dataset != null) {
            int rowCount = dataset.getRowCount();
            List<?> columnKeys = dataset.getColumnKeys();
            if (!isContainCJKCharacter(columnKeys.toArray())) {
                domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$
            }
            ((BarRenderer) render).setItemMargin(-0.40 * rowCount);

            // TDQ-12621 add Tooltip for Lable
            for (Object colKey : columnKeys) {
                domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString());
            }
        }
        domainAxis.setUpperMargin(0.1);
        // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..."
        domainAxis.setMaximumCategoryLabelLines(1);

        // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well
        // not do this when the bar is horizontal Orientation
        if (orientation == null) {
            ((BarRenderer) render).setMaximumBarWidth(0.2);
        }
        // TDQ-5111~
    }
    // ~10998
}

From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index",
            mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false,
            false);/*from   w w  w .j a  v  a 2  s . c om*/

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    return chart;
}