Example usage for org.jfree.chart ChartFactory createScatterPlot

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

Introduction

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

Prototype

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

Source Link

Document

Creates a scatter plot with default settings.

Usage

From source file:stratego.neural.net.NeuralNetTest.java

private static void plotDataSet(List<NamedDataSet> ArraySetList) {

    XYSeriesCollection plotData = new XYSeriesCollection();

    for (NamedDataSet ns : ArraySetList) {
        XYSeries series = new XYSeries(ns.getName());
        double[] data = ns.getArray();
        for (int i = 0; i < data.length; i++) {
            series.add((double) i, data[i]);
        }//ww  w  .j ava  2 s.c o  m

        plotData.addSeries(series);
    }

    String title = "Overfitting Data";
    String xAxisLabel = "Epochs";
    String yAxisLabel = "Accuracy";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean legend = true; // might wanna set this to true at some point, but research the library
    boolean tooltips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation,
            legend, tooltips, urls);

    JPanel panel = new ChartPanel(chart);

    JFrame f = new JFrame();
    f.add(panel);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.pack();
    f.setTitle("Overfitting data");

    f.setVisible(true);
}

From source file:lu.lippmann.cdb.ext.hydviga.data.StationsDataProvider.java

private ChartPanel buildMapPanel(final Instances dataSet, final int xidx, final int yidx,
        final boolean withLegend) {
    final XYSeriesCollection data = new XYSeriesCollection();
    final Map<Integer, java.util.List<Instance>> filteredInstances = new HashMap<Integer, java.util.List<Instance>>();
    final int classIndex = dataSet.classIndex();
    if (classIndex < 0) {
        final XYSeries series = new XYSeries("Serie", false);
        for (int i = 0; i < dataSet.numInstances(); i++) {
            series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
        }//from ww w .jav a2s  .com
        data.addSeries(series);
    } else {
        final Set<String> pvs = new TreeSet<String>(
                WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex));
        int p = 0;
        for (final String pv : pvs) {
            final XYSeries series = new XYSeries(pv, false);
            for (int i = 0; i < dataSet.numInstances(); i++) {
                if (dataSet.instance(i).stringValue(classIndex).equals(pv)) {
                    if (!filteredInstances.containsKey(p)) {
                        filteredInstances.put(p, new ArrayList<Instance>());
                    }
                    filteredInstances.get(p).add(dataSet.instance(i));

                    series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx));
                }
            }
            data.addSeries(series);

            p++;
        }

    }

    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            dataSet.attribute(xidx).name(), // x axis label
            dataSet.attribute(yidx).name(), // y axis label
            data, // data
            PlotOrientation.VERTICAL, withLegend, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setBackgroundImage(shapeImage);

    final XYItemRenderer renderer = xyPlot.getRenderer();
    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            if (classIndex < 0) {
                return InstanceFormatter.htmlFormat(dataSet.instance(item), true);
            } else {
                return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true);
            }
        }
    };

    xyPlot.getRangeAxis().setVisible(false);
    xyPlot.getDomainAxis().setVisible(false);

    xyPlot.getRangeAxis().setLowerBound(60000);
    xyPlot.getRangeAxis().setUpperBound(135000);
    xyPlot.getDomainAxis().setLowerBound(45000);
    xyPlot.getDomainAxis().setUpperBound(110000);

    xyPlot.setDomainGridlinesVisible(false);
    xyPlot.setRangeGridlinesVisible(false);

    xyPlot.setBackgroundPaint(Color.white);

    int nbSeries;
    if (classIndex < 0) {
        nbSeries = 1;
    } else {
        nbSeries = filteredInstances.keySet().size();
    }

    for (int i = 0; i < nbSeries; i++) {
        renderer.setSeriesToolTipGenerator(i, gen);
    }

    final XYItemLabelGenerator lg = new XYItemLabelGenerator() {
        @Override
        public String generateLabel(final XYDataset ds, final int series, final int item) {
            final Instance iii = filteredInstances.get(series).get(item);
            if (iii.stringValue(3).equals(SELECTED_STATUS)) {
                final String label = iii.stringValue(0);
                return label.substring(0, label.length() - 4);
            } else
                return null;
        }
    };
    xyPlot.getRenderer().setBaseItemLabelGenerator(lg);
    xyPlot.getRenderer().setBaseItemLabelsVisible(true);
    xyPlot.getRenderer().setBaseItemLabelFont(new Font("Tahoma", Font.PLAIN, 12));

    xyPlot.getRenderer().setSeriesPaint(1, Color.BLUE);
    xyPlot.getRenderer().setSeriesPaint(0, new Color(210, 210, 210));
    xyPlot.getRenderer().setSeriesPaint(2, Color.DARK_GRAY);

    //System.out.println("shape -> "+xyPlot.getRenderer().getSeriesStroke(0));

    final ChartPanel cp = new ChartPanel(chart);
    cp.setDomainZoomable(false);
    cp.setRangeZoomable(false);

    return cp;
}

From source file:lu.lippmann.cdb.lab.mds.UniversalMDS.java

public JXPanel buildMDSViewFromDataSet(Instances ds, MDSTypeEnum type) throws Exception {

    final XYSeriesCollection dataset = new XYSeriesCollection();

    final JFreeChart chart = ChartFactory.createScatterPlot("", // title 
            "X", "Y", // axis labels 
            dataset, // dataset 
            PlotOrientation.VERTICAL, true, // legend? yes 
            true, // tooltips? yes 
            false // URLs? no 
    );//from  w  w w. j ava2  s  . c o  m

    final XYPlot xyPlot = (XYPlot) chart.getPlot();

    chart.setTitle(type.name() + " MDS");

    Attribute clsAttribute = null;
    int nbClass = 1;
    if (ds.classIndex() != -1) {
        clsAttribute = ds.classAttribute();
        nbClass = clsAttribute.numValues();
    }

    final List<XYSeries> lseries = new ArrayList<XYSeries>();
    if (nbClass <= 1) {
        lseries.add(new XYSeries("Serie #1", false));
    } else {
        for (int i = 0; i < nbClass; i++) {
            lseries.add(new XYSeries(clsAttribute.value(i), false));
        }
    }
    dataset.removeAllSeries();

    /**
     * Initialize filtered series
     */
    final List<Instances> filteredInstances = new ArrayList<Instances>();
    for (int i = 0; i < lseries.size(); i++) {
        filteredInstances.add(new Instances(ds, 0));
    }

    for (int i = 0; i < ds.numInstances(); i++) {
        final Instance oInst = ds.instance(i);
        int indexOfSerie = 0;
        if (oInst.classIndex() != -1) {
            indexOfSerie = (int) oInst.value(oInst.classAttribute());
        }
        lseries.get(indexOfSerie).add(coordinates[i][0], coordinates[i][1]);
        filteredInstances.get(indexOfSerie).add(oInst);
    }

    final List<Paint> colors = new ArrayList<Paint>();

    for (final XYSeries series : lseries) {
        dataset.addSeries(series);
    }

    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return InstanceFormatter.htmlFormat(filteredInstances.get(series).instance(item), true);
        }
    };

    final Shape shape = new Ellipse2D.Float(0f, 0f, 5f, 5f);

    ((XYLineAndShapeRenderer) xyPlot.getRenderer()).setUseOutlinePaint(true);

    for (int p = 0; p < nbClass; p++) {
        xyPlot.getRenderer().setSeriesToolTipGenerator(p, gen);
        ((XYLineAndShapeRenderer) xyPlot.getRenderer()).setLegendShape(p, shape);
        xyPlot.getRenderer().setSeriesOutlinePaint(p, Color.BLACK);
    }

    for (int ii = 0; ii < nbClass; ii++) {
        colors.add(xyPlot.getRenderer().getItemPaint(ii, 0));
    }

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(new TitledBorder("MDS Projection"));
    chartPanel.setBackground(Color.WHITE);

    final JXPanel allPanel = new JXPanel();
    allPanel.setLayout(new BorderLayout());
    allPanel.add(chartPanel, BorderLayout.CENTER);

    return allPanel;
}

From source file:edu.unc.LCCC.caBIG.DWD.javaCode.visualization.SetUpPlotWindow.java

public static JPanel createXYScatterPlotChart(XYDataset data, String x, String y, int w, int h) {
    //XYDataset data = new SampleXYDataset2();
    JFreeChart chart = ChartFactory.createScatterPlot(null, // the title of the chart
            x, // the label for the X axis
            y, // the label for the Y axis
            data, // the dataset for the chart
            PlotOrientation.VERTICAL, // the orientation of the chart
            true, // a flag specifying whether or not a legend is required
            true, // a flag specifying whether or not tooltips should be generated
            false); // a flag specifying whether or not the chart should generate URLs

    XYPlot plot = (XYPlot) chart.getXYPlot();

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    /*/*www .j  a va  2s  .  c  om*/
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
             
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setFixedDimension(50);
            
    ValueAxis yAxis = plot.getRangeAxis();
    */
    //StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    //renderer.setSeriesPaint(0, java.awt.Color.red);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(w, h));

    return chartPanel;
}

From source file:SciTK.PlotXYError.java

/** More (common) initialization routines */
private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*from   ww w.j a  va 2 s  .c  o m*/

    XYErrorRenderer renderer = new XYErrorRenderer();
    XYPlot plot = chart.getXYPlot(); // the plot itself
    plot.setRenderer(renderer);

    // for some reason default is white, change it to black:
    setGridlineColor(Color.BLACK);

    super.window_title = window_title;
    super.initUI();
}

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 va2  s.  c  o  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:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            false, true, false);//from  ww  w .j  a  va  2s  .c  o  m

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.white);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //defines colors 
    int seriesN = dataset.getSeriesCount();
    if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            Color color = new Color(Integer.decode(defaultColor).intValue());
            if (colorMap != null && colorMap.size() > 0)
                color = (Color) colorMap.get(serieName);
            if (color != null)
                renderer.setSeriesPaint(i, color);
        }
    }

    // add un interval  marker for the Y axis...
    if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("")
            && !yMarkerEndInt.equals("")) {
        Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt),
                Double.parseDouble(yMarkerEndInt));
        intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerY.setPaint(
                new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue()));
        //intMarkerY.setLabel(yMarkerLabel);
        intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(intMarkerY, Layer.BACKGROUND);
    }
    // add un interval  marker for the X axis...
    if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("")
            && !xMarkerEndInt.equals("")) {
        Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt),
                Double.parseDouble(xMarkerEndInt));
        intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerX.setPaint(
                new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue()));
        //intMarkerX.setLabel(xMarkerLabel);
        intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(intMarkerX, Layer.BACKGROUND);
    }
    // add a labelled marker for the Y axis...
    if (yMarkerValue != null && !yMarkerValue.equals("")) {
        Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue));
        markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!yMarkerColor.equals(""))
            markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue()));
        markerY.setLabel(yMarkerLabel);
        markerY.setLabelFont(new Font("Arial", Font.BOLD, 11));
        markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(markerY, Layer.BACKGROUND);
    }
    // add a labelled marker for the X axis...
    if (xMarkerValue != null && !xMarkerValue.equals("")) {
        Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue));
        markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!xMarkerColor.equals(""))
            markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue()));
        markerX.setLabel(xMarkerLabel);
        markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(markerX, Layer.BACKGROUND);
    }

    if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) {
        if (Double.valueOf(xRangeLow).doubleValue() > xMin)
            xRangeLow = String.valueOf(xMin);
        if (Double.valueOf(xRangeHigh).doubleValue() < xMax)
            xRangeHigh = String.valueOf(xMax);
        ValueAxis rangeAxis = plot.getRangeAxis();
        //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
        rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
    } else {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAutoRange(true);
        rangeAxis.setRange(xMin, xMax);
    }

    if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) {
        if (Double.valueOf(yRangeLow).doubleValue() > yMin)
            yRangeLow = String.valueOf(yMin);
        if (Double.valueOf(yRangeHigh).doubleValue() < yMax)
            yRangeHigh = String.valueOf(yMax);
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setAutoRangeIncludesZero(false);
    } else {
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRange(true);
        domainAxis.setRange(yMin, yMax);
        domainAxis.setAutoRangeIncludesZero(false);
    }

    //add annotations if requested
    if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) {
        if (annotationMap == null || annotationMap.size() == 0)
            logger.error("Annotations on the chart are requested but the annotationMap is null!");
        else {
            int cont = 1;
            for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) {
                String text = (String) iterator.next();
                String pos = (String) annotationMap.get(text);
                double x = Double.parseDouble(pos.substring(0, pos.indexOf("__")));
                double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2));
                //default up position
                XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1,
                        x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                if (cont % 2 != 0)
                    //dx
                    annotation = new XYTextAnnotation(text, y,
                            x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                else
                    //sx
                    //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1));
                    annotation = new XYTextAnnotation(text, y, x - (text.length() - 1));

                annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
                //annotation.setRotationAngle(Math.PI / 4.0);
                annotation.setRotationAngle(0.0); // horizontal
                plot.addAnnotation(annotation);
                cont++;
            }
            renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
        }
    } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) {
        renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
    }
    if (legend == true) {

        drawLegend(chart);
    }
    return chart;
}

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  a  v a 2 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:GUI.PlotCreator.java

private ChartPanel createSeaCurrentDirectionByHPanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Sea Current Direction Plot", "H",
            "Sea Current Direction", createSeaCurrentDirectionDataByH(), PlotOrientation.VERTICAL, true, true,
            false);//w  ww .ja va2 s  . c o m
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    //XYItemRenderer renderer = xyPlot.getRenderer();
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    xyPlot.setRenderer(renderer);
    return new ChartPanel(jfreechart);
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background,
        Color backgroundAlternative, Color main) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    // Set dot shape of the currently appended Series
    renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main);
    renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables);
    renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    // Set range axis
    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);//ww  w .j  a v a2  s .  co  m
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setUpperMargin(0);

        TickUnitSource units = NumberAxis.createIntegerTickUnits();
        rangeAxis.setStandardTickUnits(units);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    // Build subchart
    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC,
            PlotOrientation.VERTICAL, false, false, false);

    // Get subplot from subchart
    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    // CHART BACKGROUD COLOR
    if (combinedPlot.getSubplots().size() % 2 == 0) {
        subplot.setBackgroundPaint(background); // Hue, saturation, brightness
    } else {
        subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness
    }

    // Add significance Threshold to subplot
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to hetzyThreshold
    if (showlables) {
        thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold));
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    // Chromosome Axis Labels
    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setLabelAngle(1.0);
    chrAxis.setAutoRangeIncludesZero(false);
    chrAxis.setAxisLineVisible(true);

    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    //      chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC);
    //      TickUnitSource units = NumberAxis.createIntegerTickUnits();
    //      chrAxis.setStandardTickUnits(units);

    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}