Example usage for org.jfree.chart ChartFactory createBubbleChart

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

Introduction

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

Prototype

public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel,
        XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a bubble chart with default settings.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java

private JFreeChart createChart(final Expression aExpression) {
    if (aExpression instanceof BarLineChartExpression) {
        final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS
        final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS
        final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS

        final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer());
        plot.setRenderer(1, new LineAndShapeRenderer());

        // add lines dataset and axis to plot
        plot.setDataset(1, createDataset());
        plot.setRangeAxis(1, linesAxis);

        // map lines to second axis
        plot.mapDatasetToRangeAxis(1, 1);

        // set rendering order
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        // set location of second axis
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

        return new JFreeChart("Bar Line Chart", plot);
    }// w  ww  .j  av  a2  s  . c om

    if (aExpression instanceof RingChartExpression) {
        return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS
    }
    if (aExpression instanceof AreaChartExpression) {
        return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof BarChartExpression) {
        return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS

    }
    if (aExpression instanceof LineChartExpression) {
        return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof MultiPieChartExpression) {
        return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN,
                true, false, false);// NON-NLS
    }
    if (aExpression instanceof PieChartExpression) {
        return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS
    }
    if (aExpression instanceof WaterfallChartExpressions) {
        return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(),
                PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof BubbleChartExpression) {
        return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof ExtendedXYLineChartExpression) {
        return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof ScatterPlotChartExpression) {
        return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof XYAreaLineChartExpression) {
        final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS
        final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS
        final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS

        final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer());
        plot.setRenderer(1, new XYLineAndShapeRenderer());

        // add lines dataset and axis to plot
        plot.setDataset(1, createXYZDataset());
        plot.setRangeAxis(1, linesAxis);

        // map lines to second axis
        plot.mapDatasetToRangeAxis(1, 1);

        // set rendering order
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        // set location of second axis
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

        return new JFreeChart("XY Area Line Chart", plot);// NON-NLS
    }
    if (aExpression instanceof XYAreaChartExpression) {
        return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof XYBarChartExpression) {
        return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof XYLineChartExpression) {
        return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(),
                PlotOrientation.VERTICAL, true, false, false);// NON-NLS
    }
    if (aExpression instanceof RadarChartExpression) {
        final SpiderWebPlot plot = new SpiderWebPlot(createDataset());
        return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    }
    if (aExpression instanceof ThermometerChartExpression) {
        final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0));
        final ThermometerPlot plot = new ThermometerPlot(dataset);

        return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    }
    return null;
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithXYDataSet(ChartData chartData) {
    XYDataset dataset = (XYDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean legend = chartData.isLegend();

    JFreeChart chart = null;//  w ww.j a v a 2 s  . co  m
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    if (type.equalsIgnoreCase("timeseries")) {
        chart = ChartFactory.createTimeSeriesChart("", xAxis, yAxis, dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("xyline")) {
        chart = ChartFactory.createXYLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("polar")) {
        chart = ChartFactory.createPolarChart("", dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("scatter")) {
        chart = ChartFactory.createScatterPlot("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xyarea")) {
        chart = ChartFactory.createXYAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xysteparea")) {
        chart = ChartFactory.createXYStepAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("xystep")) {
        chart = ChartFactory.createXYStepChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("bubble")) {
        chart = ChartFactory.createBubbleChart("", xAxis, yAxis, (XYZDataset) dataset, plotOrientation, legend,
                true, false);
    } else if (type.equalsIgnoreCase("candlestick")) {
        chart = ChartFactory.createCandlestickChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("boxandwhisker")) {
        chart = ChartFactory.createBoxAndWhiskerChart("", xAxis, yAxis, (BoxAndWhiskerXYDataset) dataset,
                legend);
    } else if (type.equalsIgnoreCase("highlow")) {
        chart = ChartFactory.createHighLowChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("histogram")) {
        chart = ChartFactory.createHistogram("", xAxis, yAxis, (IntervalXYDataset) dataset, plotOrientation,
                legend, true, false);
    } else if (type.equalsIgnoreCase("wind")) {
        chart = ChartFactory.createWindPlot("", xAxis, yAxis, (WindDataset) dataset, legend, true, false);
    }

    if (chart.getPlot() instanceof XYPlot) {
        chart.getXYPlot().setDomainGridlinesVisible(chartData.isDomainGridLines());
        chart.getXYPlot().setRangeGridlinesVisible(chartData.isRangeGridLines());

        if (chartData.getGenerateMap() != null)
            chart.getXYPlot().getRenderer().setURLGenerator(new StandardXYURLGenerator(""));
    }

    setXYSeriesColors(chart, chartData);

    setXYExtensions(chart, chartData);

    return chart;
}

From source file:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java

@Override
public void updatePlotter() {
    final DataTable dataTable = getDataTable();

    prepareData();//from   w w w.  jav a 2  s .  c o  m

    JFreeChart chart = ChartFactory.createBubbleChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            xyzDataSet, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // URLs
    );

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) {
        if (nominal) {
            int size = xyzDataSet.getSeriesCount();
            chart = ChartFactory.createBubbleChart(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    colorColumn >= 0 && size < 100 ? true : false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            XYBubbleRenderer renderer = (XYBubbleRenderer) chart.getXYPlot().getRenderer();
            renderer.setBaseOutlinePaint(Color.BLACK);

            if (size > 1) {
                for (int i = 0; i < size; i++) {
                    renderer.setSeriesPaint(i, getColorProvider(true).getPointColor(i / (double) (size - 1)));
                    renderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 7, 7));
                }
            } else {
                renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
                renderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 7, 7));
            }

            // legend settings
            LegendTitle legend = chart.getLegend();
            if (legend != null) {
                legend.setPosition(RectangleEdge.TOP);
                legend.setFrame(BlockBorder.NONE);
                legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
                legend.setItemFont(LABEL_FONT);
            }
        } else {
            chart = ChartFactory.createScatterPlot(null, // chart title
                    null, // domain axis label
                    null, // range axis label
                    xyzDataSet, // data
                    PlotOrientation.VERTICAL, // orientation
                    false, // include legend
                    true, // tooltips
                    false // URLs
            );

            // renderer settings
            ColorizedBubbleRenderer renderer = new ColorizedBubbleRenderer(this.colors);
            renderer.setBaseOutlinePaint(Color.BLACK);
            chart.getXYPlot().setRenderer(renderer);

            // legend settings
            chart.addLegend(new LegendTitle(renderer) {

                private static final long serialVersionUID = 1288380309936848376L;

                @Override
                public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area,
                        java.lang.Object params) {
                    if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn)
                            || dataTable.isDateTime(colorColumn)) {
                        drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7),
                                dataTable, colorColumn, minColor, maxColor);
                        return new BlockResult();
                    } else {
                        final String minColorString = Tools.formatNumber(minColor);
                        final String maxColorString = Tools.formatNumber(maxColor);
                        drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90),
                                (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn),
                                minColorString, maxColorString);
                        return new BlockResult();
                    }
                }

                @Override
                public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) {
                    draw(g2, area, null);
                }

            });
        }
    }

    // GENERAL CHART SETTINGS

    // set the background colors for the chart...
    chart.setBackgroundPaint(Color.WHITE);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.getPlot().setForegroundAlpha(0.7f);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    if (axis[X_AXIS] >= 0) {
        if (dataTable.isNominal(axis[X_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[X_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[X_AXIS], i);
            }
            plot.setDomainAxis(new SymbolAxis(dataTable.getColumnName(axis[X_AXIS]), values));
        } else if (dataTable.isDate(axis[X_AXIS]) || dataTable.isDateTime(axis[X_AXIS])) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(axis[X_AXIS]));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setDomainAxis(domainAxis);
        } else {
            if (logScales[X_AXIS]) {
                LogAxis domainAxis = new LogAxis(dataTable.getColumnName(axis[X_AXIS]));
                domainAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
                plot.setDomainAxis(domainAxis);
            } else {
                plot.setDomainAxis(new NumberAxis(dataTable.getColumnName(axis[X_AXIS])));
            }
        }
        Range range = getRangeForDimension(axis[X_AXIS]);
        if (range != null) {
            plot.getDomainAxis().setRange(range, true, false);
        } else {
            plot.getDomainAxis().setAutoRange(true);
        }
    }
    plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getDomainAxis().setTickLabelFont(LABEL_FONT);

    // rotate labels
    if (isLabelRotating()) {
        plot.getDomainAxis().setTickLabelsVisible(true);
        plot.getDomainAxis().setVerticalTickLabels(true);
    }

    // range axis
    if (axis[Y_AXIS] >= 0) {
        if (dataTable.isNominal(axis[Y_AXIS])) {
            String[] values = new String[dataTable.getNumberOfValues(axis[Y_AXIS])];
            for (int i = 0; i < values.length; i++) {
                values[i] = dataTable.mapIndex(axis[Y_AXIS], i);
            }
            plot.setRangeAxis(new SymbolAxis(dataTable.getColumnName(axis[Y_AXIS]), values));
        } else if (dataTable.isDate(axis[Y_AXIS]) || dataTable.isDateTime(axis[Y_AXIS])) {
            DateAxis rangeAxis = new DateAxis(dataTable.getColumnName(axis[Y_AXIS]));
            rangeAxis.setTimeZone(Tools.getPreferredTimeZone());
            plot.setRangeAxis(rangeAxis);
        } else {
            plot.setRangeAxis(new NumberAxis(dataTable.getColumnName(axis[Y_AXIS])));
        }
        Range range = getRangeForDimension(axis[Y_AXIS]);
        if (range != null) {
            plot.getRangeAxis().setRange(range, true, false);
        } else {
            plot.getRangeAxis().setAutoRange(true);
        }
    }
    plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD);
    plot.getRangeAxis().setTickLabelFont(LABEL_FONT);

    AbstractChartPanel panel = getPlotterPanel();
    // Chart Panel Settings
    if (panel == null) {
        panel = createPanel(chart);
    } else {
        panel.setChart(chart);
    }

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}

From source file:org.squale.squaleweb.util.graph.BubbleMaker.java

/**
 * Factorisation du code commun  la gnration du graphe
 * //from  w ww .j ava2  s.c o  m
 * @return graphe de type Bubble
 */
private JFreeChart getCommonChart() {
    // Cration du graphe de type Bubble
    JFreeChart chart = ChartFactory.createBubbleChart(mTitle, mXLabel, mYLabel, mDataSet,
            PlotOrientation.VERTICAL, mShowLegend, true, false);

    ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
    ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis();

    // Dtermination des bornes en abscisse et en ordonne
    double maxDomain = Math.max(domainAxis.getUpperBound(), DEFAULT_VERTICAL_AXIS_POS + DEFAULT_AXIS_MARGIN)
            + 1;
    double minDomain = 0;
    double maxRange = Math.max(rangeAxis.getUpperBound(), DEFAULT_HORIZONTAL_AXIS_POS + DEFAULT_AXIS_MARGIN)
            + 1;
    double minRange = 0;

    // Mise  l'chelle logarithmique des axes
    LogarithmicAxis newDomainAxis = new LogarithmicAxis(domainAxis.getLabel());
    LogarithmicAxis newRangeAxis = new LogarithmicAxis(rangeAxis.getLabel());

    // Affectation des bornes en abscisse et en ordonne
    newDomainAxis.setLowerBound(minDomain);
    newDomainAxis.setUpperBound(maxDomain);
    newRangeAxis.setLowerBound(minRange);
    newRangeAxis.setUpperBound(maxRange);
    chart.getXYPlot().setDomainAxis(newDomainAxis);
    chart.getXYPlot().setRangeAxis(newRangeAxis);

    // Affichage de la rpartition des mthodes selon les critres
    displayRepartitionSubtitles(chart);

    // Annotations
    XYLineAnnotation horizontalAxis = new XYLineAnnotation(minDomain, DEFAULT_HORIZONTAL_AXIS_POS, maxDomain,
            DEFAULT_HORIZONTAL_AXIS_POS);
    XYLineAnnotation verticalAxis = new XYLineAnnotation(DEFAULT_VERTICAL_AXIS_POS, minRange,
            DEFAULT_VERTICAL_AXIS_POS, maxRange);

    chart.getXYPlot().addAnnotation(horizontalAxis);
    chart.getXYPlot().addAnnotation(verticalAxis);
    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  av a  2 s  .c  o 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: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);//from  w  ww .j  a v a 2  s . c  om

    // 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.chartthemes.spring.GenericChartTheme.java

protected JFreeChart createBubbleChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBubbleChart(
            evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()),
            (XYZDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true,
            false);/* w w w  .j a  v a  2s  . c om*/

    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);

    // 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:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected JFreeChart createBubbleChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBubbleChart(
            evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()),
            (XYZDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true,
            false);//from w  w w.j  a v  a  2  s.c  om

    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);

    // 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

protected JFreeChart createBubbleChart() throws JRException {
    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createBubbleChart(
            evaluateTextExpression(getChart().getTitleExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getXAxisLabelExpression()),
            evaluateTextExpression(((JRBubblePlot) getPlot()).getYAxisLabelExpression()),
            (XYZDataset) getDataset(), getPlot().getOrientationValue().getOrientation(), isShowLegend(), true,
            false);/*w  w w  .j  a  va 2s  .  co  m*/

    configureChart(jfreeChart);

    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);

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(), bubblePlot.getXAxisLabelColor(),
            bubblePlot.getXAxisTickLabelFont(), bubblePlot.getXAxisTickLabelColor(),
            bubblePlot.getXAxisTickLabelMask(), bubblePlot.getXAxisVerticalTickLabels(),
            bubblePlot.getXAxisLineColor(), 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.getYAxisLineColor(), true,
            (Comparable<?>) evaluateExpression(bubblePlot.getRangeAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(bubblePlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private JFreeChart createBubbleChart() throws QueryException {
    bubbleDataset = new DefaultXYZDataset();

    // x, y are inverted for jfree bubble chart!
    // that's why we use minX & maxX values to compute Tu (tickUnit)
    String chartTitle = replaceParameters(chart.getTitle().getTitle());
    chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language));
    String xLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    String yLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    JFreeChart jfreechart = ChartFactory.createBubbleChart(chartTitle, xLegend, // x-axis Label
            yLegend, // y-axis Label
            bubbleDataset, PlotOrientation.HORIZONTAL, true, true, false);

    // hide border
    jfreechart.setBorderVisible(false);//from   w  ww . j  ava2s  .c  o m

    // title
    setTitle(jfreechart);

    boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart();

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(transparency);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();

    DecimalFormat decimalformat;
    DecimalFormat percentageFormat;
    if (chart.getYTooltipPattern() == null) {
        decimalformat = new DecimalFormat("#");
        percentageFormat = new DecimalFormat("0.00%");
    } else {
        decimalformat = new DecimalFormat(chart.getYTooltipPattern());
        percentageFormat = decimalformat;
    }

    if (showValues) {
        // increase a little bit the range axis to view all item label values over bars
        xyplot.getRangeAxis().setUpperMargin(0.2);
    }

    // grid axis visibility & colors 
    if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) {
        xyplot.setDomainGridlinesVisible(false);
    } else {
        if (chart.getXGridColor() != null) {
            xyplot.setDomainGridlinePaint(chart.getXGridColor());
        } else {
            xyplot.setDomainGridlinePaint(Color.BLACK);
        }
    }
    if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) {
        xyplot.setRangeGridlinesVisible(false);
    } else {
        if (chart.getYGridColor() != null) {
            xyplot.setRangeGridlinePaint(chart.getYGridColor());
        } else {
            xyplot.setRangeGridlinePaint(Color.BLACK);
        }
    }

    // chart background
    xyplot.setBackgroundPaint(chart.getBackground());

    // labels color
    xyplot.getDomainAxis().setTickLabelPaint(chart.getXColor());
    xyplot.getRangeAxis().setTickLabelPaint(chart.getYColor());

    // legend color
    xyplot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor());
    xyplot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor());

    // legend font
    xyplot.getDomainAxis().setLabelFont(chart.getXLegend().getFont());
    xyplot.getRangeAxis().setLabelFont(chart.getYLegend().getFont());

    // axis color
    xyplot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor());
    xyplot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor());

    // hide labels
    if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) {
        xyplot.getDomainAxis().setTickLabelsVisible(false);
        xyplot.getDomainAxis().setTickMarksVisible(false);
    }
    if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) {
        xyplot.getRangeAxis().setTickLabelsVisible(false);
        xyplot.getRangeAxis().setTickMarksVisible(false);
    }

    // label orientation
    ValueAxis domainAxis = xyplot.getDomainAxis();
    if (chart.getXorientation() == Chart.VERTICAL) {
        domainAxis.setLabelAngle(Math.PI / 2);
    } else if (chart.getXorientation() == Chart.DIAGONAL) {
        domainAxis.setLabelAngle(Math.PI / 4);
    } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) {
        domainAxis.setLabelAngle(Math.PI / 8);
    }

    // labels fonts
    xyplot.getDomainAxis().setTickLabelFont(chart.getXLabelFont());
    xyplot.getRangeAxis().setTickLabelFont(chart.getYLabelFont());

    createChart(xyplot.getRangeAxis(), new Object[4]);

    double minX = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = Double.MIN_VALUE;
    double maxZ = Double.MIN_VALUE;
    for (String serie : bubbleData.keySet()) {
        XYZList xyzList = bubbleData.get(serie);
        List<Number> yList = xyzList.getyList();
        for (Number n : yList) {
            minY = Math.min(minY, n.doubleValue());
            maxY = Math.max(maxY, n.doubleValue());
        }
        List<Number> xList = xyzList.getxList();
        for (Number n : xList) {
            minX = Math.min(minX, n.doubleValue());
            maxX = Math.max(maxX, n.doubleValue());
        }
        List<Number> zList = xyzList.getzList();
        for (Number n : zList) {
            maxZ = Math.max(maxZ, n.doubleValue());
        }
    }

    double tu = Math.floor((maxX - minX) / 5 + 0.5d);
    NumberTickUnit rUnit = new NumberTickUnit(tu);
    ((NumberAxis) xyplot.getRangeAxis()).setTickUnit(rUnit);

    // make the bubble with text fit on X axis (which is shown vertically!)
    xyplot.getDomainAxis().setUpperMargin(0.2);
    xyplot.getDomainAxis().setLowerMargin(0.2);

    for (String serie : bubbleData.keySet()) {
        XYZList xyzList = bubbleData.get(serie);
        double[][] data = { getDoubleArray(xyzList.getyList()), getDoubleArray(xyzList.getxList()),
                getZDoubleArray(xyzList.getzList(), tu, maxZ) };
        bubbleDataset.addSeries(serie, data);
    }

    int series = bubbleData.keySet().size();
    for (int i = 0; i < series; i++) {
        xyitemrenderer.setSeriesPaint(i, chart.getForegrounds().get(i));
        if (showValues) {
            xyitemrenderer.setSeriesItemLabelsVisible(i, true);
            xyitemrenderer.setSeriesItemLabelGenerator(i,
                    new StandardXYItemLabelGenerator("{2}", decimalformat, percentageFormat));
        }
    }

    // show labels on bubbles
    xyitemrenderer.setBaseItemLabelsVisible(true);
    xyitemrenderer.setBaseItemLabelGenerator(new LegendXYItemLabelGenerator());
    return jfreechart;
}