Example usage for org.jfree.chart ChartFactory setChartTheme

List of usage examples for org.jfree.chart ChartFactory setChartTheme

Introduction

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

Prototype

public static void setChartTheme(ChartTheme theme) 

Source Link

Document

Sets the current chart theme.

Usage

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

protected JFreeChart createBar3DChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBarChart3D(
            evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBar3DPlot) getPlot()).getCategoryAxisLabelExpression()),
            evaluateTextExpression(((JRBar3DPlot) getPlot()).getValueAxisLabelExpression()),
            (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(),
            true, false);// w  w w . j av  a 2 s .  c  o  m

    configureChart(jfreeChart);

    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    JRBar3DPlot bar3DPlot = (JRBar3DPlot) getPlot();

    BarRenderer3D barRenderer3D = new BarRenderer3D(
            bar3DPlot.getXOffsetDouble() == null ? BarRenderer3D.DEFAULT_X_OFFSET
                    : bar3DPlot.getXOffsetDouble(),
            bar3DPlot.getYOffsetDouble() == null ? BarRenderer3D.DEFAULT_Y_OFFSET
                    : bar3DPlot.getYOffsetDouble());

    boolean isShowLabels = bar3DPlot.getShowLabels() == null ? false : bar3DPlot.getShowLabels();
    barRenderer3D.setBaseItemLabelsVisible(isShowLabels);
    if (isShowLabels) {
        JRItemLabel itemLabel = bar3DPlot.getItemLabel();

        barRenderer3D.setBaseItemLabelFont(
                fontUtil.getAwtFont(getFont(itemLabel == null ? null : itemLabel.getFont()), getLocale()));

        if (itemLabel != null) {
            if (itemLabel.getColor() != null) {
                barRenderer3D.setBaseItemLabelPaint(itemLabel.getColor());
            } else {
                barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
            }
            //            categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
            //            if (itemLabel.getMask() != null)
            //            {
            //               barRenderer3D.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            //                     StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
            //                     new DecimalFormat(itemLabel.getMask())));
            //            }
            //            else
            //            {
            barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            //            }
        } else {
            barRenderer3D.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            barRenderer3D.setBaseItemLabelPaint(getChart().getForecolor());
        }
    }

    categoryPlot.setRenderer(barRenderer3D);

    // Handle the axis formating for the category axis
    configureAxis(categoryPlot.getDomainAxis(), bar3DPlot.getCategoryAxisLabelFont(),
            bar3DPlot.getCategoryAxisLabelColor(), bar3DPlot.getCategoryAxisTickLabelFont(),
            bar3DPlot.getCategoryAxisTickLabelColor(), bar3DPlot.getCategoryAxisTickLabelMask(),
            bar3DPlot.getCategoryAxisVerticalTickLabels(), bar3DPlot.getCategoryAxisLineColor(), false,
            (Comparable<?>) evaluateExpression(bar3DPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(bar3DPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(categoryPlot.getRangeAxis(), bar3DPlot.getValueAxisLabelFont(),
            bar3DPlot.getValueAxisLabelColor(), bar3DPlot.getValueAxisTickLabelFont(),
            bar3DPlot.getValueAxisTickLabelColor(), bar3DPlot.getValueAxisTickLabelMask(),
            bar3DPlot.getValueAxisVerticalTickLabels(), bar3DPlot.getValueAxisLineColor(), true,
            (Comparable<?>) evaluateExpression(bar3DPlot.getRangeAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(bar3DPlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

/**
 *
 *//*  www .jav  a  2s  . com*/
protected JFreeChart createBarChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBarChart(evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()),
            evaluateTextExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()),
            (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(),
            true, false);

    configureChart(jfreeChart, getPlot());

    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    //plot.setNoDataMessage("No data to display");

    JRBarPlot barPlot = (JRBarPlot) getPlot();
    boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks();
    boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels();

    categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks);
    categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the category axis
    configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(),
            barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(),
            barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(),
            barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getOwnCategoryAxisLineColor(),
            getDomainAxisSettings(),
            (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMaxValueExpression()));

    ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks);
    ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the value axis
    Comparable<?> rangeAxisMaxValue = (Comparable<?>) evaluateExpression(
            barPlot.getRangeAxisMaxValueExpression());
    configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(),
            barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(),
            barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(),
            barPlot.getValueAxisVerticalTickLabels(), barPlot.getOwnValueAxisLineColor(),
            getRangeAxisSettings(),
            (Comparable<?>) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), rangeAxisMaxValue);

    BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer();
    boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels();
    categoryRenderer.setBaseItemLabelsVisible(isShowLabels);
    if (isShowLabels) {
        if (rangeAxisMaxValue == null) {
            //in case the bars are horizontal and there was no range max value specified, 
            //we try to make the axis a little longer for labels to fit on the plot
            Axis axis = categoryPlot.getRangeAxis();
            if (axis instanceof ValueAxis) {
                if (!(axis instanceof DateAxis)) {
                    float rangeAxisMaxRatio = 1f;

                    if (barPlot.getOrientationValue() == PlotOrientationEnum.HORIZONTAL) {
                        rangeAxisMaxRatio = JRPropertiesUtil
                                .getInstance(getChartContext().getJasperReportsContext())
                                .getFloatProperty(getChart(),
                                        "net.sf.jasperreports.chart.bar.horizontal.range.max.value.ratio",
                                        1.25f);
                    } else {
                        rangeAxisMaxRatio = JRPropertiesUtil
                                .getInstance(getChartContext().getJasperReportsContext())
                                .getFloatProperty(getChart(),
                                        "net.sf.jasperreports.chart.bar.vertical.range.max.value.ratio", 1.1f);
                    }

                    ((ValueAxis) axis).setUpperBound(((ValueAxis) axis).getUpperBound() * rangeAxisMaxRatio);
                }
            }
        }

        JRItemLabel itemLabel = barPlot.getItemLabel();
        JRFont font = itemLabel != null && itemLabel.getFont() != null ? itemLabel.getFont()
                : new JRBaseFont(getChart(), null);
        categoryRenderer.setBaseItemLabelFont(getFontUtil().getAwtFont(font, getLocale()));
        if (itemLabel != null) {
            if (itemLabel.getColor() != null) {
                categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor());
            } else {
                categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor());
            }
            //            categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
            //            if (itemLabel.getMask() != null)
            //            {
            //               categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            //                     StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
            //                     new DecimalFormat(itemLabel.getMask())));
            //            }
            //            else
            //            {
            categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            //            }
        } else {
            categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor());
        }
    }

    categoryRenderer.setShadowVisible(false);

    return jfreeChart;
}

From source file:org.apache.jmeter.visualizers.CreateReport.java

/**
 * Creates a table; widths are set with setWidths().
 * @return a PdfPTable//  ww  w . j av a2s  .c om
 * @throws DocumentException
 */

//createGraphs("Average Response Time of samples for each Request","Average(ms)",2);
public Image createGraphs(String chartName, String colName, int colNo) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < model.getRowCount(); i++)
        dataset.setValue((long) model.getValueAt(i, colNo), "Average", model.getValueAt(i, 0).toString());
    ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());

    final JFreeChart chart = ChartFactory.createBarChart3D(chartName, // chart title
            "Requests", // domain axis label

            "Average (ms)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));
    final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(0.05);

    try {
        //java.io.OutputStream out= new OutputStream(new FileOutputStream(BASEPATH+"//MyFile.jpg"));
        ChartUtilities.saveChartAsJPEG(new File(BASEPATH + "//MyFile.jpg"), chart, 500, 400);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    Image img = null;
    try {
        img = Image.getInstance(BASEPATH + "//MyFile.jpg");
    } catch (BadElementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return img;
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * DOC xqliu Comment method "createLineChart".
 * //  w  w w  . j a v a  2s  .  c om
 * @param title
 * @param dataset
 * @param showLegend
 * @return
 */
public static JFreeChart createLineChart(String title, XYDataset dataset, boolean showLegend) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    final JFreeChart chart = ChartFactory.createXYLineChart(null, title,
            Messages.getString("TopChartFactory.Percent"), dataset, PlotOrientation.VERTICAL, //$NON-NLS-1$
            showLegend, false, false);

    final XYPlot plot = chart.getXYPlot();

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected JFreeChart createBubbleChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBubbleChart(
            (String) evaluateExpression(getChart().getTitleExpression()),
            (String) evaluateExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()),
            (String) evaluateExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()),
            (XYZDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRBubblePlot bubblePlot = (JRBubblePlot) getPlot();
    int scaleType = bubblePlot.getScaleTypeValue() == null ? ScaleTypeEnum.ON_RANGE_AXIS.getValue()
            : bubblePlot.getScaleTypeValue().getValue();
    XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer(scaleType);
    xyPlot.setRenderer(bubbleRenderer);/*from w  ww .  j  a v  a 2 s .co  m*/

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(), bubblePlot.getXAxisLabelColor(),
            bubblePlot.getXAxisTickLabelFont(), bubblePlot.getXAxisTickLabelColor(),
            bubblePlot.getXAxisTickLabelMask(), bubblePlot.getXAxisVerticalTickLabels(),
            bubblePlot.getOwnXAxisLineColor(), false,
            (Comparable) evaluateExpression(bubblePlot.getDomainAxisMinValueExpression()),
            (Comparable) evaluateExpression(bubblePlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), bubblePlot.getYAxisLabelFont(), bubblePlot.getYAxisLabelColor(),
            bubblePlot.getYAxisTickLabelFont(), bubblePlot.getYAxisTickLabelColor(),
            bubblePlot.getYAxisTickLabelMask(), bubblePlot.getYAxisVerticalTickLabels(),
            bubblePlot.getOwnYAxisLineColor(), true,
            (Comparable) evaluateExpression(bubblePlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(bubblePlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * //  w ww .  j  a  v  a  2s  .  com
 * DOC qiongli Comment method "createPieChart".
 * 
 * @param title
 * @param dataset
 * @param showLegend
 * @param toolTips,if show the toolTips.
 * @param urls
 * @return
 */
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean showLegend, boolean toolTips,
        boolean urls) {
    // ADD msjian TDQ-5112 2012-4-10: after upgrate to jfreechart-1.0.12.jar, change the default chart wallPaint
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    // TDQ-5112~
    return ChartFactory.createPieChart(title, dataset, showLegend, toolTips, urls);
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

public static JFreeChart createDuplicateRecordPieChart(String title, PieDataset dataset, boolean showLegend,
        boolean toolTips, boolean urls) {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart pieChart = ChartFactory.createPieChart(title, dataset, showLegend, toolTips, urls);
    ChartDecorator.decorateDuplicatePieChart(pieChart);
    return pieChart;
}

From source file:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

private boolean writeDetailedFactorAnalysis(ExpressionExperiment ee, OutputStream os) throws Exception {
    SVDValueObject svdo = svdService.getSvdFactorAnalysis(ee.getId());
    if (svdo == null)
        return false;

    if (svdo.getFactors().isEmpty() && svdo.getDates().isEmpty()) {
        return false;
    }/*from w ww  .j  a  va 2  s. c o m*/
    Map<Integer, Map<Long, Double>> factorCorrelations = svdo.getFactorCorrelations();
    // Map<Integer, Map<Long, Double>> factorPvalues = svdo.getFactorPvalues();
    Map<Integer, Double> dateCorrelations = svdo.getDateCorrelations();

    assert ee.getId().equals(svdo.getId());

    ee = expressionExperimentService.thawLite(ee); // need the experimental design
    int maxWidth = 30;
    Map<Long, String> efs = this.getFactorNames(ee, maxWidth);
    Map<Long, ExperimentalFactor> efIdMap = EntityUtils
            .getIdMap(ee.getExperimentalDesign().getExperimentalFactors());
    Collection<Long> continuousFactors = new HashSet<>();
    for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
        boolean isContinous = ExperimentalDesignUtils.isContinuous(ef);
        if (isContinous) {
            continuousFactors.add(ef.getId());
        }
    }

    /*
     * Make plots of the dates vs. PCs, factors vs. PCs.
     */
    int MAX_COMP = 3;

    Map<Long, List<JFreeChart>> charts = new LinkedHashMap<>();
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    /*
     * FACTORS
     */
    String componentShorthand = "PC";
    for (Integer component : factorCorrelations.keySet()) {

        if (component >= MAX_COMP)
            break;
        String xaxisLabel = componentShorthand + (component + 1);

        for (Long efId : factorCorrelations.get(component).keySet()) {

            /*
             * Should not happen.
             */
            if (!efs.containsKey(efId)) {
                log.warn("No experimental factor with id " + efId);
                continue;
            }

            if (!svdo.getFactors().containsKey(efId)) {
                // this should not happen.
                continue;
            }

            boolean isCategorical = !continuousFactors.contains(efId);

            Map<Long, String> categories = new HashMap<>();

            if (isCategorical) {
                this.getCategories(efIdMap, efId, categories);
            }

            if (!charts.containsKey(efId)) {
                charts.put(efId, new ArrayList<JFreeChart>());
            }

            Double a = factorCorrelations.get(component).get(efId);
            String plotname = (efs.get(efId) == null ? "?" : efs.get(efId)) + " " + xaxisLabel; // unique?

            if (a != null && !Double.isNaN(a)) {
                String title = plotname + " " + String.format("%.2f", a);
                List<Double> values = svdo.getFactors().get(efId);
                Double[] eigenGene = this.getEigenGene(svdo, component);
                assert values.size() == eigenGene.length;

                /*
                 * Plot eigengene vs values, add correlation to the plot
                 */
                JFreeChart chart;
                if (isCategorical) {

                    /*
                     * Categorical factor
                     */

                    // use the absolute value of the correlation, since direction is arbitrary.
                    title = plotname + " " + String.format("r=%.2f", Math.abs(a));

                    DefaultMultiValueCategoryDataset dataset = new DefaultMultiValueCategoryDataset();

                    /*
                     * What this code does is organize the factor values by the groups.
                     */
                    Map<String, List<Double>> groupedValues = new TreeMap<>();
                    for (int i = 0; i < values.size(); i++) {
                        Long fvId = values.get(i).longValue();
                        String fvValue = categories.get(fvId);
                        if (fvValue == null) {
                            /*
                             * Problem ...eg gill2006fateinocean id=1748 -- missing values. We just don't plot
                             * anything for this sample.
                             */
                            continue; // is this all we need to do?
                        }
                        if (!groupedValues.containsKey(fvValue)) {
                            groupedValues.put(fvValue, new ArrayList<Double>());
                        }

                        groupedValues.get(fvValue).add(eigenGene[i]);

                        if (log.isDebugEnabled())
                            log.debug(fvValue + " " + values.get(i));
                    }

                    for (String key : groupedValues.keySet()) {
                        dataset.add(groupedValues.get(key), plotname, key);
                    }

                    // don't show the name of the X axis: it's redundant with the title.
                    NumberAxis rangeAxis = new NumberAxis(xaxisLabel);
                    rangeAxis.setAutoRangeIncludesZero(false);
                    // rangeAxis.setAutoRange( false );
                    rangeAxis.setAutoRangeMinimumSize(4.0);
                    // rangeAxis.setRange( new Range( -2, 2 ) );

                    CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis(null), rangeAxis,
                            new ScatterRenderer());
                    plot.setRangeGridlinesVisible(false);
                    plot.setDomainGridlinesVisible(false);

                    chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, false);

                    ScatterRenderer renderer = (ScatterRenderer) plot.getRenderer();
                    float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
                    renderer.setSeriesFillPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
                    renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
                    renderer.setUseOutlinePaint(false);
                    renderer.setUseFillPaint(true);
                    renderer.setBaseFillPaint(Color.white);
                    CategoryAxis domainAxis = plot.getDomainAxis();
                    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                } else {

                    /*
                     * Continuous value factor
                     */

                    DefaultXYDataset series = new DefaultXYDataset();
                    series.addSeries(plotname,
                            new double[][] { ArrayUtils.toPrimitive(values.toArray(new Double[] {})),
                                    ArrayUtils.toPrimitive(eigenGene) });

                    // don't show x-axis label, which would otherwise be efs.get( efId )
                    chart = ChartFactory.createScatterPlot(title, null, xaxisLabel, series,
                            PlotOrientation.VERTICAL, false, false, false);
                    XYPlot plot = chart.getXYPlot();
                    plot.setRangeGridlinesVisible(false);
                    plot.setDomainGridlinesVisible(false);

                    XYItemRenderer renderer = plot.getRenderer();
                    renderer.setBasePaint(Color.white);
                    renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
                    float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
                    renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
                    plot.setRenderer(renderer);
                }

                chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));

                charts.get(efId).add(chart);
            }
        }
    }

    /*
     * DATES
     */
    charts.put(-1L, new ArrayList<JFreeChart>());
    for (Integer component : dateCorrelations.keySet()) {
        String xaxisLabel = componentShorthand + (component + 1);

        List<Date> dates = svdo.getDates();
        if (dates.isEmpty())
            break;

        long secspan = ubic.basecode.util.DateUtil.numberOfSecondsBetweenDates(dates);

        if (component >= MAX_COMP)
            break;
        Double a = dateCorrelations.get(component);

        if (a != null && !Double.isNaN(a)) {
            Double[] eigenGene = svdo.getvMatrix().getColObj(component);

            /*
             * Plot eigengene vs values, add correlation to the plot
             */
            TimeSeries series = new TimeSeries("Dates vs. eigen" + (component + 1));
            int i = 0;
            for (Date d : dates) {
                // if span is less than an hour, retain the minute.
                if (secspan < 60 * 60) {
                    series.addOrUpdate(new Minute(d), eigenGene[i++]);
                } else {
                    series.addOrUpdate(new Hour(d), eigenGene[i++]);
                }

            }
            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.addSeries(series);

            JFreeChart chart = ChartFactory.createTimeSeriesChart(
                    "Dates: " + xaxisLabel + " " + String.format("r=%.2f", a), null, xaxisLabel, dataset, false,
                    false, false);

            XYPlot xyPlot = chart.getXYPlot();

            chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));

            // standard renderer makes lines.
            XYDotRenderer renderer = new XYDotRenderer();
            renderer.setBaseFillPaint(Color.white);
            renderer.setDotHeight(3);
            renderer.setDotWidth(3);
            renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); // has no effect, need dotheight.
            float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
            renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
            ValueAxis domainAxis = xyPlot.getDomainAxis();
            domainAxis.setVerticalTickLabels(true);
            xyPlot.setRenderer(renderer);
            xyPlot.setRangeGridlinesVisible(false);
            xyPlot.setDomainGridlinesVisible(false);
            charts.get(-1L).add(chart);

        }
    }

    /*
     * Plot in a grid, with each factor as a column. FIXME What if we have too many factors to fit on the screen?
     */
    int columns = (int) Math.ceil(charts.size());
    int perChartSize = ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX;
    BufferedImage image = new BufferedImage(columns * perChartSize, MAX_COMP * perChartSize,
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    int currentX = 0;
    int currentY = 0;
    for (Long id : charts.keySet()) {
        for (JFreeChart chart : charts.get(id)) {
            this.addChartToGraphics(chart, g2, currentX, currentY, perChartSize, perChartSize);
            if (currentY + perChartSize < MAX_COMP * perChartSize) {
                currentY += perChartSize;
            } else {
                currentY = 0;
                currentX += perChartSize;
            }
        }
    }

    os.write(ChartUtilities.encodeAsPNG(image));
    return true;
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected JFreeChart createBubbleChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBubbleChart(
            (String) evaluateExpression(getChart().getTitleExpression()),
            (String) evaluateExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()),
            (String) evaluateExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()),
            (XYZDataset) getDataset(), getPlot().getOrientation(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRBubblePlot bubblePlot = (JRBubblePlot) getPlot();
    int scaleType = bubblePlot.getScaleTypeValue() == null ? ScaleTypeEnum.ON_RANGE_AXIS.getValue()
            : bubblePlot.getScaleTypeValue().getValue();
    XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer(scaleType);
    xyPlot.setRenderer(bubbleRenderer);/*  w w w  .j a v  a2s  . co m*/

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(), bubblePlot.getXAxisLabelColor(),
            bubblePlot.getXAxisTickLabelFont(), bubblePlot.getXAxisTickLabelColor(),
            bubblePlot.getXAxisTickLabelMask(), bubblePlot.getXAxisVerticalTickLabels(),
            bubblePlot.getOwnXAxisLineColor(), getDomainAxisSettings(),
            (Comparable) evaluateExpression(bubblePlot.getDomainAxisMinValueExpression()),
            (Comparable) evaluateExpression(bubblePlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), bubblePlot.getYAxisLabelFont(), bubblePlot.getYAxisLabelColor(),
            bubblePlot.getYAxisTickLabelFont(), bubblePlot.getYAxisTickLabelColor(),
            bubblePlot.getYAxisTickLabelMask(), bubblePlot.getYAxisVerticalTickLabels(),
            bubblePlot.getOwnYAxisLineColor(), getRangeAxisSettings(),
            (Comparable) evaluateExpression(bubblePlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(bubblePlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

/**
 *
 *///from  w w  w  . ja  va 2s.c  o m
protected JFreeChart createBarChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBarChart(evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBarPlot) getPlot()).getCategoryAxisLabelExpression()),
            evaluateTextExpression(((JRBarPlot) getPlot()).getValueAxisLabelExpression()),
            (CategoryDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(),
            true, false);

    configureChart(jfreeChart);

    CategoryPlot categoryPlot = (CategoryPlot) jfreeChart.getPlot();
    //plot.setNoDataMessage("No data to display");

    JRBarPlot barPlot = (JRBarPlot) getPlot();
    boolean isShowTickMarks = barPlot.getShowTickMarks() == null ? true : barPlot.getShowTickMarks();
    boolean isShowTickLabels = barPlot.getShowTickLabels() == null ? true : barPlot.getShowTickLabels();

    categoryPlot.getDomainAxis().setTickMarksVisible(isShowTickMarks);
    categoryPlot.getDomainAxis().setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the category axis
    configureAxis(categoryPlot.getDomainAxis(), barPlot.getCategoryAxisLabelFont(),
            barPlot.getCategoryAxisLabelColor(), barPlot.getCategoryAxisTickLabelFont(),
            barPlot.getCategoryAxisTickLabelColor(), barPlot.getCategoryAxisTickLabelMask(),
            barPlot.getCategoryAxisVerticalTickLabels(), barPlot.getCategoryAxisLineColor(), false,
            (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(barPlot.getDomainAxisMaxValueExpression()));

    ((NumberAxis) categoryPlot.getRangeAxis()).setTickMarksVisible(isShowTickMarks);
    ((NumberAxis) categoryPlot.getRangeAxis()).setTickLabelsVisible(isShowTickLabels);
    // Handle the axis formating for the value axis
    Comparable<?> rangeAxisMaxValue = (Comparable<?>) evaluateExpression(
            barPlot.getRangeAxisMaxValueExpression());
    configureAxis(categoryPlot.getRangeAxis(), barPlot.getValueAxisLabelFont(),
            barPlot.getValueAxisLabelColor(), barPlot.getValueAxisTickLabelFont(),
            barPlot.getValueAxisTickLabelColor(), barPlot.getValueAxisTickLabelMask(),
            barPlot.getValueAxisVerticalTickLabels(), barPlot.getValueAxisLineColor(), true,
            (Comparable<?>) evaluateExpression(barPlot.getRangeAxisMinValueExpression()), rangeAxisMaxValue);

    BarRenderer categoryRenderer = (BarRenderer) categoryPlot.getRenderer();
    boolean isShowLabels = barPlot.getShowLabels() == null ? false : barPlot.getShowLabels();
    categoryRenderer.setBaseItemLabelsVisible(isShowLabels);
    if (isShowLabels) {
        if (rangeAxisMaxValue == null) {
            //in case the bars are horizontal and there was no range max value specified, 
            //we try to make the axis a little longer for labels to fit on the plot
            Axis axis = categoryPlot.getRangeAxis();
            if (axis instanceof ValueAxis) {
                if (!(axis instanceof DateAxis)) {
                    float rangeAxisMaxRatio = 1f;

                    if (barPlot.getOrientationValue() == PlotOrientationEnum.HORIZONTAL) {
                        rangeAxisMaxRatio = JRPropertiesUtil.getInstance(chartContext.getJasperReportsContext())
                                .getFloatProperty(getChart(),
                                        "net.sf.jasperreports.chart.bar.horizontal.range.max.value.ratio",
                                        1.25f);
                    } else {
                        rangeAxisMaxRatio = JRPropertiesUtil.getInstance(chartContext.getJasperReportsContext())
                                .getFloatProperty(getChart(),
                                        "net.sf.jasperreports.chart.bar.vertical.range.max.value.ratio", 1.1f);
                    }

                    ((ValueAxis) axis).setUpperBound(((ValueAxis) axis).getUpperBound() * rangeAxisMaxRatio);
                }
            }
        }

        JRItemLabel itemLabel = barPlot.getItemLabel();

        categoryRenderer.setBaseItemLabelFont(
                fontUtil.getAwtFont(getFont(itemLabel == null ? null : itemLabel.getFont()), getLocale()));

        if (itemLabel != null) {
            if (itemLabel.getColor() != null) {
                categoryRenderer.setBaseItemLabelPaint(itemLabel.getColor());
            } else {
                categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor());
            }
            //            categoryRenderer.setBaseFillPaint(itemLabel.getBackgroundColor());
            //            if (itemLabel.getMask() != null)
            //            {
            //               categoryRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            //                     StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, 
            //                     new DecimalFormat(itemLabel.getMask())));
            //            }
            //            else
            //            {
            categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            //            }
        } else {
            categoryRenderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) getLabelGenerator());
            categoryRenderer.setBaseItemLabelPaint(getChart().getForecolor());
        }
    }
    categoryRenderer.setShadowVisible(false);

    return jfreeChart;
}