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

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

Introduction

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

Prototype

public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) 

Source Link

Document

Creates a new plot with the specified dataset, axes and renderer.

Usage

From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV1_5.EICPlot.java

public EICPlot(List<List<NavigableMap<Double, Double>>> clusters, List<Double> colors, List<List<String>> info,
        List<NavigableMap<Double, Double>> modelPeaks) {
    super(null, true);

    setBackground(Color.white);/*  w  w  w.j  av  a 2 s.  c  om*/
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    NumberAxis xAxis = new NumberAxis("Retention Time");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setUpperMargin(0);
    xAxis.setLowerMargin(0);

    NumberAxis yAxis = new NumberAxis("Intensity");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setUpperMargin(0);
    yAxis.setLowerMargin(0);

    xyDataset = new XYSeriesCollection();
    colorDataset = new ArrayList<>();
    toolTips = new ArrayList<>();

    int seriesID = 0;

    for (int i = 0; i < clusters.size(); ++i) {
        List<NavigableMap<Double, Double>> cluster = clusters.get(i);
        double color = colors.get(i);

        for (int j = 0; j < cluster.size(); ++j) {
            XYSeries series = new XYSeries(seriesID++);

            for (Entry<Double, Double> e : cluster.get(j).entrySet())
                series.add(e.getKey(), e.getValue());

            xyDataset.addSeries(series);
            colorDataset.add(color);
            toolTips.add(info.get(i).get(j));
        }
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() {
        @Override
        public Paint getItemPaint(int row, int col) {
            double c = colorDataset.get(row);
            return Color.getHSBColor((float) c, 1.0f, 1.0f);
        }
    };

    renderer.setDefaultShapesVisible(false);
    renderer.setDefaultToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                return toolTips.get(series);
            } catch (NullPointerException | IndexOutOfBoundsException e) {
                return "";
            }
        }
    });

    XYPlot plot = new XYPlot(xyDataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

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

    super.setChart(chart);
}

From source file:PlotsBuilding.PlotPanel.java

private JFreeChart createChart(XYDataset xyDataset, ArrayList<Integer> seriesCount, double y1, double y2) {

    NumberAxis domainAxis = new NumberAxis("x");
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setPositiveArrowVisible(true);
    NumberAxis rangeAxis = new NumberAxis("y");
    rangeAxis.setRange(y1, y2);/*from w  w  w  .j a v  a  2s . co  m*/
    rangeAxis.setPositiveArrowVisible(true);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    int start = 0;
    int color = 50;
    for (Object series : seriesCount) {
        for (int i = start; i < start + (int) series; i++) {
            Color s = new Color(color);
            renderer.setSeriesPaint(i, s);
            renderer.setSeriesVisibleInLegend(i, false);
            renderer.setSeriesVisibleInLegend(start, true);
        }
        start = start + (int) series;
        color *= 100;
    }
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    XYPlot plot = new XYPlot(xyDataset, domainAxis, rangeAxis, renderer);
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    plot.setOrientation(orientation);
    plot.setBackgroundPaint(Color.white);
    chart = new JFreeChart(plot);
    chart.setBackgroundPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);
    chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP);
    return chart;
}

From source file:org.spantus.exp.segment.exec.DrawSegmentComparision.java

/**
 * initialize/*w w  w  .  ja v  a2  s  .co  m*/
 */
public void init() {
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);
    plot.setOrientation(PlotOrientation.VERTICAL);

    XYSeries[] seriesArr = createSeries(getWavName(), getMarkerName());
    for (XYSeries series : seriesArr) {
        final XYSeriesCollection data1 = new XYSeriesCollection(series);
        final XYItemRenderer renderer1 = new StandardXYItemRenderer();
        final NumberAxis rangeAxis1 = new NumberAxis(series.getDescription());
        final XYPlot subplot = new XYPlot(data1, null, rangeAxis1, renderer1);
        plot.add(subplot, 1);
    }

    final JFreeChart chart = new JFreeChart("Segmentation Result", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    setContentPane(chartPanel);
    chartPanel.setPreferredSize(new Dimension(500, 270));
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("individual income"), new NumberAxis("delta utils"),
            null);//from www.ja  v a  2s.c  om
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsQuantilesChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot(this.dataset, new NumberAxis("population deciles sorted by income"),
            new NumberAxis("delta utils"), null);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
    plot.setRenderer(renderer);//from  ww  w.  j  ava  2s. c  o m

    JFreeChart jchart = new JFreeChart("", plot);
    return jchart;
}

From source file:org.jfree.chart.demo.OverlaidXYPlotDemo.java

/**
 * Creates an overlaid chart.// w w  w .  j  a v a  2 s.c  om
 *
 * @return The chart.
 */
private JFreeChart createOverlaidChart() {

    // create plot ...
    final IntervalXYDataset data1 = createDataset1();
    final XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    final DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    final ValueAxis rangeAxis = new NumberAxis("Value");
    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);
    final double x = new Day(9, SerialDate.MARCH, 2002).getMiddleMillisecond();
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", x, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);

    // add a second dataset and renderer...
    final XYDataset data2 = createDataset2();
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, data2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Overlaid Plot Example", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:com.projity.pm.graphic.chart.ChartHelper.java

/**
 * Creates a new chart./*  w  ww.  j a  v a2 s.  co  m*/
 * 
 * @param dataset
 *            the dataset.
 * 
 * @return The chart.
 */
public static JFreeChart createBarChart(final XYDataset dataset) {
    ValueAxis domainAxis = null;
    NumberAxis axis = new NumberAxis(null);
    axis.setAutoRangeIncludesZero(false);
    domainAxis = axis;

    ValueAxis valueAxis = new NumberAxis(null);
    XYItemRenderer barRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA,
            new StandardXYToolTipGenerator(), null);

    XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, barRenderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    removeAxisAndInsets(chart);
    return chart;
}

From source file:r2d2e.solution.moduloteste.teste.GraficoD2.java

/**
 * Creates a combined chart./* w w w .java2 s .  com*/
 *
 * @return the combined chart.
 */
private JFreeChart createCombinedChart() {

    // create subplot 1...
    final XYDataset data1 = collection;
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Nvel (cm)");
    final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    /*
    final XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);
    */

    // create subplot 2...
    final XYDataset data2 = collection2;
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Tenso (volts)");
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // create subplot 3...
    final XYDataset data3 = collection3;
    final XYItemRenderer renderer3 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis3 = new NumberAxis("Tenso (volts)");
    final XYPlot subplot3 = new XYPlot(data3, null, rangeAxis3, renderer3);
    subplot3.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Tempo"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.add(subplot3, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart("Grficos", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

}

From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java

/**
 * Write a PNG image representation of the Graph to the given output 
 * stream/*from  w w w  .  j a  v a2 s.  co  m*/
 * 
 * @param out The output stream to write the PNG bytes to
 * @throws IOException Indicates a problem writing to the output stream
 */
public void writeGraphImage(int numServersDisplayed, OutputStream out) throws IOException {
    ValueAxis xAxis = new DateAxis(MonitorProperties.units(DATE_TIME));
    NumberAxis yAxis = new NumberAxis(yAxisUnits);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYPlot xyPlotLine = new XYPlot(xySeriesCollection, xAxis, yAxis,
            new StandardXYItemRenderer(StandardXYItemRenderer.LINES));
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, xyPlotLine, true);
    chart.setBackgroundPaint(java.awt.Color.white);
    // Increase size of graph height to accommodate large legends for when many servers in the domain
    int graphAdditionalHeight = GRAPH_INCREMENT_HEIGHT
            * ((int) (numServersDisplayed / GRAPH_INCREMENT_SERVER_RATIO));
    BufferedImage graphImage = chart.createBufferedImage(GRAPH_WIDTH,
            INITIAL_GRAPH_HEIGHT + graphAdditionalHeight,
            new ChartRenderingInfo(new StandardEntityCollection()));
    addNoDataLogoIfEmpty(graphImage);
    ChartUtilities.writeBufferedImageAsPNG(out, graphImage); // Could try extra two PNG related params: encodeAlpha and compression
}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

public XYPlot drawXYItemPlot() {

    // Set up renderer
    XYItemRenderer throughputRenderer = new StandardXYItemRenderer();
    throughputRenderer.setSeriesPaint(0, Color.red);

    // Normalize the throughput axis so that it represents max value
    NumberAxis axis = new NumberAxis();
    axis.setVisible(false);//from  w  w  w.ja v  a2s  .  c  om

    // Create plot
    XYPlot throughputPlot = new XYPlot(null, null, axis, throughputRenderer);
    throughputPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    throughputPlot.getRangeAxis().setVisible(false);

    return throughputPlot;
}