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:org.jfree.chart.demo.ImageMapDemo3.java

/**
 * Starting point for the demo./*  w  w w .  jav a 2  s . c  om*/
 *
 * @param args  ignored.
 *
 * @throws ParseException if there is a problem parsing dates.
 */
public static void main(final String[] args) throws ParseException {

    //  Create a sample dataset
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    final XYSeries dataSeries = new XYSeries("Curve data");
    final ArrayList toolTips = new ArrayList();
    dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22);
    toolTips.add("1D - 5.22");
    dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18);
    toolTips.add("2D - 5.18");
    dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23);
    toolTips.add("3D - 5.23");
    dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15);
    toolTips.add("4D - 5.15");
    dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22);
    toolTips.add("5D - 5.22");
    dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25);
    toolTips.add("6D - 5.25");
    dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31);
    toolTips.add("7D - 5.31");
    dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36);
    toolTips.add("8D - 5.36");
    final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
    final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator();
    ttg.addToolTipSeries(toolTips);

    //  Create the chart
    final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp");
    final ValueAxis timeAxis = new DateAxis("");
    final NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null);
    final StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
            StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg);
    sxyir.setShapesFilled(true);
    plot.setRenderer(sxyir);
    final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("xychart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("xychart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"xychart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    NumberAxis numberaxis1 = new NumberAxis("Y");
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    XYPlot xyplot = new XYPlot(intervalxydataset, numberaxis, numberaxis1, xyerrorrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    JFreeChart jfreechart = new JFreeChart("XYErrorRenderer Demo 1", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    return jfreechart;
}

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

private static JFreeChart createChart(XYDataset xydataset) {
    SymbolAxis symbolaxis = new SymbolAxis("Domain", new String[] { "A", "B", "C", "D" });
    SymbolAxis symbolaxis1 = new SymbolAxis("Range", new String[] { "V", "X", "Y", "Z" });
    symbolaxis1.setUpperMargin(0.0D);/* ww  w .j  a  v  a2 s.co m*/
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(false, true);
    XYPlot xyplot = new XYPlot(xydataset, symbolaxis, symbolaxis1, xylineandshaperenderer);
    JFreeChart jfreechart = new JFreeChart("SymbolicAxis Demo 1", xyplot);
    return jfreechart;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    NumberAxis numberaxis1 = new NumberAxis("Y");
    XYErrorRenderer xyerrorrenderer = new XYErrorRenderer();
    xyerrorrenderer.setBaseLinesVisible(true);
    xyerrorrenderer.setBaseShapesVisible(false);
    XYPlot xyplot = new XYPlot(intervalxydataset, numberaxis, numberaxis1, xyerrorrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    JFreeChart jfreechart = new JFreeChart("XYErrorRenderer Demo 2", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    return jfreechart;
}

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

public static JPanel createDemoPanel() {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    XYPlot xyplot = new XYPlot(createSampleData(), numberaxis, numberaxis1, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("XYSplineRenderer", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    return chartpanel;
}

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

private static JFreeChart createChart(IntervalXYDataset intervalxydataset) {
    DateAxis dateaxis = new DateAxis("Date");
    NumberAxis numberaxis = new NumberAxis("Y");
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    xybarrenderer.setUseYInterval(true);
    XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer);
    JFreeChart jfreechart = new JFreeChart(xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);
    return jfreechart;
}

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

private static JFreeChart createChart(VectorXYDataset dataset) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.01D);/*ww w.  j a va2s.c o m*/
    xAxis.setUpperMargin(0.01D);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.01D);
    yAxis.setUpperMargin(0.01D);
    yAxis.setAutoRangeIncludesZero(false);
    //
    VectorRenderer renderer = new VectorRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    plot.setOutlinePaint(Color.black);
    JFreeChart chart = new JFreeChart("Vector Plot Demo 1", plot);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

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

private static JFreeChart createChart(VectorXYDataset dataset) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.01D);//  w  ww. ja  v  a 2 s .  c  o m
    xAxis.setUpperMargin(0.01D);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.01D);
    yAxis.setUpperMargin(0.01D);
    yAxis.setAutoRangeIncludesZero(false);
    //
    VectorRenderer renderer = new VectorRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    plot.setOutlinePaint(Color.black);
    JFreeChart chart = new JFreeChart("Vector Renderer Demo 1", plot);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:no.met.jtimeseries.chart.ErrorPlot.java

public static XYPlot getMarinogramErrorPlot() {
    XYItemRenderer renderer = new StandardXYItemRenderer();
    NumberAxis rangeAxis = new NumberAxis();
    XYPlot plot = new XYPlot(null, null, rangeAxis, renderer);
    XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 0.5, 0.5);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    plot.addAnnotation(annotation);/*from  www .  j  a  va2s.  c om*/
    return plot;
}

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

private static JFreeChart createChart() {
    IntervalXYDataset dataset1 = createDataset1();
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    NumberAxis valueAxis = new NumberAxis("Value");
    XYPlot plot = new XYPlot(dataset1, domainAxis, valueAxis, renderer1);
    XYDataset dataset2 = createDataset2();
    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, dataset2);/*  ww w. j  a v a2  s  . c  o m*/
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return new JFreeChart("Overlaid XYPlot Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}