Example usage for org.jfree.chart.plot XYPlot setRenderer

List of usage examples for org.jfree.chart.plot XYPlot setRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setRenderer.

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param fragments//w  w  w.ja  v a  2  s .co  m
 * @param valueVar
 * @param useRT
 * @return
 */
public XYPlot provide1DPlot(List<IFileFragment> fragments, String valueVar, boolean useRT) {
    String[] labels = new String[fragments.size()];
    Array[] arrays = new Array[fragments.size()];
    Array[] domains = new Array[fragments.size()];
    IFileFragment fragment = null;
    List<XYAnnotation> annotations = new ArrayList<>();
    int i = 0;
    for (IFileFragment file : fragments) {
        fragment = file;
        labels[i] = fragment.getName() + " TIC";
        arrays[i] = fragment.getChild(valueVar).getArray();
        //Factory.getInstance().getConfiguration().getString("var.total_intensity","total_intensity")).getArray();
        if (useRT) {
            try {
                domains[i] = fragment.getChild("scan_acquisition_time").getArray();
            } catch (ResourceNotAvailableException rne) {
            }
        }
        //            annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT, valueVar));
        //            annotations.addAll(generatePeakShapes(fragment, useRT, new Color(0,
        //                    0, 255, 192), new Color(0, 0, 255, 32), valueVar));
        //            annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i], useRT));
        //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray();
        i++;
    }
    XYChart xyc = null;
    if (useRT) {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, "time[s]", "value");
    } else {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, "index", "value");
    }
    XYPlot xyp = xyc.create();
    for (XYAnnotation xya : annotations) {
        xyp.addAnnotation(xya);
    }
    xyp.setRenderer(renderer);
    //xyp.setDomainCrosshairVisible(true);
    xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            Comparable comp = xyd.getSeriesKey(i);
            double x = xyd.getXValue(i, i1);
            double y = xyd.getYValue(i, i1);
            StringBuilder sb = new StringBuilder();
            sb.append(comp);
            sb.append(": ");
            sb.append("x=");
            sb.append(x);
            sb.append(" y=");
            sb.append(y);
            return sb.toString();
        }
    });
    //        xyp.getRenderer().setDefaultEntityRadius(20);

    return xyp;
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param fragments//from ww w .  j  a  v  a  2s . c  o m
 * @param masses
 * @param massResolution
 * @param useRT
 * @return
 */
public XYPlot provide1DEICCOPlot(List<IFileFragment> fragments, double[] masses, double massResolution,
        boolean useRT) {
    int i = 0;
    IFileFragment fragment;
    String[] labels = new String[fragments.size() * masses.length];
    Array[] arrays = new Array[fragments.size() * masses.length];
    Array[] domains = new Array[fragments.size() * masses.length];
    double[] massValues = Arrays.copyOf(masses, masses.length);
    Arrays.sort(massValues);
    List<XYAnnotation> annotations = new ArrayList<>();
    int trace = 0;
    for (IFileFragment file : fragments) {
        fragment = file;
        for (int k = 0; k < massValues.length; k++) {
            double minMZ = massValues[k];
            double maxMZ = massValues[k] + massResolution;
            labels[trace] = fragment.getName() + " EICS:" + "[" + minMZ + "," + maxMZ + ")";
            Array eic = MaltcmsTools.getEIC(fragment, minMZ, maxMZ, false, false);

            arrays[trace] = eic;
            if (useRT) {
                try {
                    domains[trace] = fragment.getChild("scan_acquisition_time").getArray();
                } catch (ResourceNotAvailableException rne) {
                }
            }
            trace++;
        }
        //            annotations.addAll(getANDIChromPeakAnnotations(fragment, useRT));
        //            annotations.addAll(generatePeakShapes(fragment, useRT, new Color(0,
        //                    0, 255, 192), new Color(0, 0, 255, 32)));
        //            annotations.addAll(getCSVPeakAnnotations(fragment, arrays[i], useRT));
        //Factory.getInstance().getConfiguration().getString("var.scan_acquisition_time","scan_acquisition_time")).getArray();
        i++;
    }
    XYChart xyc = null;
    if (useRT) {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, domains, "time[s]", "value");
    } else {
        xyc = new XYChart(fragments.get(0).getName(), labels, arrays, "index", "value");
    }
    XYPlot xyp = xyc.create();
    for (XYAnnotation xya : annotations) {
        xyp.addAnnotation(xya);
    }
    xyp.setRenderer(renderer);
    xyp.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            Comparable comp = xyd.getSeriesKey(i);
            double x = xyd.getXValue(i, i1);
            double y = xyd.getYValue(i, i1);
            StringBuilder sb = new StringBuilder();
            sb.append(comp);
            sb.append(": ");
            sb.append("x=");
            sb.append(x);
            sb.append(" y=");
            sb.append(y);
            return sb.toString();
        }
    });
    return xyp;
}

From source file:com.googlecode.logVisualizer.chart.LineChartBuilder.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setNoDataMessage("No data available");
    if (dataset.getSeriesCount() > 0)
        ((NumberAxis) plot.getDomainAxis()).setUpperBound(lastXValue);
    ((NumberAxis) plot.getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesStroke(i, new BasicStroke(2));
    }//  w  ww .  jav a  2 s  .  c  o m
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);

    return chart;
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates a bubble chart with default settings.  The chart is composed of    
 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis,    
 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer}    
 * to draw the data items.    //from w  ww .ja v a2  s.  c  o  m
 *    
 * @param title  the chart title (<code>null</code> permitted).    
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).    
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param orientation  the orientation (horizontal or vertical)     
 *                     (<code>null</code> NOT permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 * @param tooltips  configure chart to generate tool tips?    
 * @param urls  configure chart to generate URLs?    
 *    
 * @return A bubble chart.    
 */
public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel,
        XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYZURLGenerator());
    }
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

From source file:com.smanempat.controller.ControllerEvaluation.java

private void showChart(int[] tempK, double[][] evalValue, JPanel panelChart, JPanel panelChart1,
        JPanel panelChart2) {/*from  w w  w.  j  av a 2s.c  om*/
    final XYSeries accuracy = new XYSeries("Accuracy");
    final XYSeries recall = new XYSeries("Recall");
    final XYSeries precision = new XYSeries("Precision");
    final XYSeriesCollection accColect = new XYSeriesCollection();

    System.out.println("tempk panjangnya " + tempK.length);
    for (int i = 0; i < tempK.length; i++) {
        accuracy.add(tempK[i], evalValue[0][i]);
        recall.add(tempK[i], evalValue[1][i]);
        precision.add(tempK[i], evalValue[2][i]);
        System.out.println("Akurasi K ke-" + tempK[i] + "= " + evalValue[0][i]);
    }
    accColect.addSeries(accuracy);
    accColect.addSeries(recall);
    accColect.addSeries(precision);
    JFreeChart xyLineChart = ChartFactory.createXYLineChart("Grafik Hasil Pengujian Multi Testing",
            "Number of Nearest Neighbor", "Persentase", accColect, PlotOrientation.VERTICAL, true, true, false);
    final XYPlot xyPlot = xyLineChart.getXYPlot();
    XYLineAndShapeRenderer xyRender = new XYLineAndShapeRenderer();
    xyRender.setSeriesPaint(0, Color.RED);
    xyRender.setSeriesPaint(1, Color.GREEN);
    xyRender.setSeriesPaint(2, Color.BLUE);
    xyRender.setSeriesStroke(0, new BasicStroke(4.0f));
    xyRender.setSeriesStroke(1, new BasicStroke(3.0f));
    xyRender.setSeriesStroke(2, new BasicStroke(2.0f));
    xyPlot.setRenderer(xyRender);
    ChartPanel cp = new ChartPanel(xyLineChart);
    panelChart.removeAll();
    panelChart.add(cp);
    panelChart.validate();

}

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

protected JFreeChart createXyAreaChart() throws JRException {
    JFreeChart jfreeChart = super.createXyAreaChart();

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    SquareXYAreaRenderer squareXyAreaRenderer = new SquareXYAreaRenderer((XYAreaRenderer) xyPlot.getRenderer());
    xyPlot.setRenderer(squareXyAreaRenderer);

    return jfreeChart;
}

From source file:vinci.project2.pkg1.View.java

/**
 * creates the actual chart w/ dimensions, et al
 *//*from  www  . j  ava 2 s  .  c  o  m*/
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Pre/Post Taxes/Totals", "Age", "Amounts ($)",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

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

    return chart;
}

From source file:course_generator.param.frmEditCurve.java

/**
 * Create the chart/*from   w ww. j a va 2s  . c  o m*/
 * @param dataset Dataset to display
 * @return Return a JFreeChart object
 */
private JFreeChart CreateChartProfil(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createXYAreaChart("", bundle.getString("frmEditCurve.chart.slope"), //"Slope"  x axis label
            bundle.getString("frmEditCurve.chart.speed"), //"speed"  y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white); // Panel background color
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    XYAreaRenderer renderer = new XYAreaRenderer();
    // Green (safe color)
    renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
    renderer.setOutline(true);
    // Width of the outline
    renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
    plot.setRenderer(renderer);

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

    return chart;
}