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:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsTotalPrediction.java

public static JPanel createPanel() {
    //Axis configuration
    NumberAxis sampleAxis = new NumberAxis("Sample");
    sampleAxis.setAutoRangeIncludesZero(false);
    NumberAxis powerAxis = new NumberAxis("Power (Watts)");
    powerAxis.setAutoRangeIncludesZero(false);

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();

    XYPlot xyplot = new XYPlot(data, sampleAxis, powerAxis, xysplinerenderer);
    for (int i = 0; i < data.getSeriesCount(); i++) {
        xyplot.getRenderer().setSeriesShape(i, new Rectangle());
    }/*  w  w  w  . j a v  a  2  s.c o m*/

    //Panel layout configuration
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

    JFreeChart jfreechart = new JFreeChart(NAME, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);

    ChartUtilities.applyCurrentTheme(jfreechart);
    ChartPanel chartpanel = new ChartPanel(jfreechart);

    return chartpanel;
}

From source file:com.itemanalysis.jmetrik.graph.histogram.HistogramChart.java

public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel,
        IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips,
        boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }/*from w w  w. ja  v a  2  s. c om*/
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    ValueAxis yAxis = new NumberAxis(yAxisLabel);

    XYItemRenderer renderer = new XYBarRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}

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

private static JFreeChart createChart(BoxAndWhiskerXYDataset boxandwhiskerxydataset) {
    DateAxis dateaxis = new DateAxis("Day");
    NumberAxis numberaxis = new NumberAxis("Value");
    XYBoxAndWhiskerRenderer xyboxandwhiskerrenderer = new XYBoxAndWhiskerRenderer();
    XYPlot xyplot = new XYPlot(boxandwhiskerxydataset, dateaxis, numberaxis, xyboxandwhiskerrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart jfreechart = new JFreeChart("Box-and-Whisker Chart Demo 2", xyplot);
    jfreechart.setBackgroundPaint(Color.white);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:rozpoznawanie_zad1_klasyf.ChartRenderer.java

public ChartRenderer(String tytul) {
    NumberAxis xAxis = new NumberAxis("Cecha 2");
    //     xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis("Cecha 1");
    //XYItemRenderer rend;
    // rend = new XYLineAndShapeRenderer(false, true);
    //XYItemRenderer rend = new XYLineAndShapeRenderer(true, false);
    XYDotRenderer rend = new XYDotRenderer();
    rend.setDotHeight(5);// w ww .  j  av a  2s. com
    rend.setDotWidth(5);
    XYPlot plot = new XYPlot(ds, xAxis, yAxis, rend);
    //      dataset.addSeries("sin", sin);

    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart fc = new JFreeChart(plot);
    cf = new ChartFrame(tytul, fc);
    cf.setSize(1280, 720);
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);//from w  ww  . ja  va  2s . co m
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

public TimePeriodValuesDemo1(String s) {
    super(s);//from   ww  w  . j  a v  a  2 s . c  om
    XYDataset xydataset = createDataset1();
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setVerticalTickLabels(true);
    dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1));
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));
    dateaxis.setLowerMargin(0.01D);
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Value");
    XYPlot xyplot = new XYPlot(xydataset, dateaxis, numberaxis, xybarrenderer);
    XYDataset xydataset1 = createDataset2();
    StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(3);
    standardxyitemrenderer.setBaseShapesFilled(true);
    xyplot.setDataset(1, xydataset1);
    xyplot.setRenderer(1, standardxyitemrenderer);
    JFreeChart jfreechart = new JFreeChart("Supply and Demand", xyplot);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.setMouseZoomable(true, false);
    setContentPane(chartpanel);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java

public static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel,
        final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips,
        final boolean urls, final boolean stacked) {
    final ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);//from ww  w  .  j  av a  2s  .  c  o  m
    final NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);

    XYToolTipGenerator toolTipGenerator = null;
    if (tooltips) {
        toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    }

    XYURLGenerator urlGenerator = null;
    if (urls) {
        urlGenerator = new StandardXYURLGenerator();
    }

    final XYAreaRenderer2 renderer;
    if (stacked) {
        renderer = new StackedXYAreaRenderer2();
    } else {
        renderer = new XYAreaRenderer2();
    }
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setURLGenerator(urlGenerator);
    plot.setRenderer(renderer);

    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:jamel.gui.charts.TimeChart.java

/**
 * Returns a new time plot.//w  w w . j ava2  s  .c  o m
 * @param timeSeries  the time series.
 * @param valueAxisLabel the value axis label.
 * @return a new time plot.
 */
private static Plot newTimePlot(TimeSeries[] timeSeries, String valueAxisLabel) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.setXPosition(TimePeriodAnchor.MIDDLE);
    for (int i = 0; i < timeSeries.length; i++) {
        TimeSeries series = timeSeries[i];
        if (series == null)
            throw new RuntimeException();
        dataset.addSeries(series);
    }
    final XYPlot plot = new XYPlot(dataset, new DateAxis(), new NumberAxis(valueAxisLabel),
            new XYLineAndShapeRenderer(true, false));
    ((DateAxis) plot.getDomainAxis()).setAutoRange(false);
    ((DateAxis) plot.getDomainAxis()).setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    plot.setDomainGridlinesVisible(false);
    return plot;
}

From source file:jamel.gui.charts.Histogram.java

/**
 * Returns a new plot.//from w  w  w.j  a va  2s  . co  m
 * @param dataset  the dataset.
 * @param hAxisLabel  the label for the x axis.
 * @param vAxisLabel  the label for the y axis.
 * @param color  the color of the chart.
 * @return the new plot.
 */
static private Plot newPlot(HistogramDataset dataset, String hAxisLabel, String vAxisLabel, Color color) {
    NumberAxis xAxis = new NumberAxis(hAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    ValueAxis yAxis = new NumberAxis(vAxisLabel);
    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);
    renderer.setMargin(0.05);
    renderer.setSeriesPaint(0, color);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

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

private static XYPlot createSubplot2(IntervalXYDataset intervalxydataset) {
    DateAxis dateaxis = new DateAxis("Date/Time");
    SymbolAxis symbolaxis = new SymbolAxis("Resources",
            new String[] { "Team A", "Team B", "Team C", "Team D", "Team E" });
    symbolaxis.setGridBandsVisible(false);
    XYBarRenderer xybarrenderer = new XYBarRenderer();
    xybarrenderer.setUseYInterval(true);
    XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, symbolaxis, xybarrenderer);
    return xyplot;
}